gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34110 - gnunet/src/sensor


From: gnunet
Subject: [GNUnet-SVN] r34110 - gnunet/src/sensor
Date: Tue, 5 Aug 2014 13:59:52 +0200

Author: otarabai
Date: 2014-08-05 13:59:52 +0200 (Tue, 05 Aug 2014)
New Revision: 34110

Added:
   gnunet/src/sensor/gnunet-service-sensor_analysis.c
   gnunet/src/sensor/gnunet-service-sensor_reporting_anomaly.c
   gnunet/src/sensor/gnunet-service-sensor_reporting_value.c
   gnunet/src/sensor/gnunet-service-sensor_update.c
Removed:
   gnunet/src/sensor/gnunet-service-sensor-analysis.c
   gnunet/src/sensor/gnunet-service-sensor-reporting.c
   gnunet/src/sensor/gnunet-service-sensor-update.c
Modified:
   gnunet/src/sensor/Makefile.am
   gnunet/src/sensor/gnunet-service-sensor.c
   gnunet/src/sensor/sensor.h
Log:
sensor: towards anomaly reporting


Modified: gnunet/src/sensor/Makefile.am
===================================================================
--- gnunet/src/sensor/Makefile.am       2014-08-04 18:05:05 UTC (rev 34109)
+++ gnunet/src/sensor/Makefile.am       2014-08-05 11:59:52 UTC (rev 34110)
@@ -36,15 +36,17 @@
 
 gnunet_service_sensor_SOURCES = \
  gnunet-service-sensor.c \
- gnunet-service-sensor-analysis.c \
- gnunet-service-sensor-reporting.c \
- gnunet-service-sensor-update.c
+ gnunet-service-sensor_analysis.c \
+ gnunet-service-sensor_reporting_value.c \
+ gnunet-service-sensor_reporting_anomaly.c \
+ gnunet-service-sensor_update.c
 gnunet_service_sensor_LDADD = \
   libgnunetsensorutil.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
   $(top_builddir)/src/cadet/libgnunetcadet.la \
+  $(top_builddir)/src/core/libgnunetcore.la \
   $(GN_LIBINTL)
 
 libgnunetsensor_la_SOURCES = \

Deleted: gnunet/src/sensor/gnunet-service-sensor-analysis.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor-analysis.c  2014-08-04 18:05:05 UTC 
(rev 34109)
+++ gnunet/src/sensor/gnunet-service-sensor-analysis.c  2014-08-05 11:59:52 UTC 
(rev 34110)
@@ -1,324 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file sensor/gnunet-service-sensor-analysis.c
- * @brief sensor service analysis functionality
- * @author Omar Tarabai
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "sensor.h"
-#include "gnunet_peerstore_service.h"
-#include "gnunet_sensor_model_plugin.h"
-
-#define LOG(kind,...) GNUNET_log_from (kind, "sensor-analysis",__VA_ARGS__)
-
-/**
- * Carries information about the analysis model
- * corresponding to one sensor
- */
-struct SensorModel
-{
-
-  /**
-   * DLL
-   */
-  struct SensorModel *prev;
-
-  /**
-   * DLL
-   */
-  struct SensorModel *next;
-
-  /**
-   * Pointer to sensor info structure
-   */
-  struct GNUNET_SENSOR_SensorInfo *sensor;
-
-  /**
-   * Watcher of sensor values
-   */
-  struct GNUNET_PEERSTORE_WatchContext *wc;
-
-  /**
-   * State of sensor. #GNUNET_YES if anomalous, #GNUNET_NO otherwise.
-   */
-  int anomalous;
-
-  /**
-   * Number of anomalous readings (positive) received in a row.
-   */
-  int positive_count;
-
-  /**
-   * Number of non-anomalous (negative) readings received in a row.
-   */
-  int negative_count;
-
-  /**
-   * Closure for model plugin.
-   * Usually, the instance of the model created for this sensor.
-   */
-  void *cls;
-
-};
-
-/**
- * Our configuration.
- */
-static const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-/*
- * Model library name
- */
-static char *model_lib_name;
-
-/**
- * Model handle
- */
-static struct GNUNET_SENSOR_ModelFunctions *model_api;
-
-/**
- * Handle to peerstore service
- */
-static struct GNUNET_PEERSTORE_Handle *peerstore;
-
-/**
- * Head of DLL of created models
- */
-static struct SensorModel *models_head;
-
-/**
- * Tail of DLL of created models
- */
-static struct SensorModel *models_tail;
-
-/**
- * My peer id
- */
-struct GNUNET_PeerIdentity peerid;
-
-/**
- * How many subsequent values required to flip anomaly label.
- * E.g. After 3 subsequent anomaly reports, status change to anomalous.
- */
-unsigned long long confirmation_count;
-
-/**
- * Destroy a created model
- */
-static void
-destroy_sensor_model (struct SensorModel *sensor_model)
-{
-  GNUNET_assert (NULL != sensor_model);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying sensor model for `%s'.\n",
-       sensor_model->sensor->name);
-  if (NULL != sensor_model->wc)
-  {
-    GNUNET_PEERSTORE_watch_cancel (sensor_model->wc);
-    sensor_model->wc = NULL;
-  }
-  if (NULL != sensor_model->cls)
-  {
-    model_api->destroy_model (sensor_model->cls);
-    sensor_model->cls = NULL;
-  }
-  GNUNET_free (sensor_model);
-  sensor_model = NULL;
-}
-
-
-/**
- * Stop the sensor analysis module
- */
-void
-SENSOR_analysis_stop ()
-{
-  struct SensorModel *sm;
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor analysis module.\n");
-  while (NULL != models_head)
-  {
-    sm = models_head;
-    GNUNET_CONTAINER_DLL_remove (models_head, models_tail, sm);
-    destroy_sensor_model (sm);
-  }
-  if (NULL != peerstore)
-  {
-    GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
-    peerstore = NULL;
-  }
-  if (NULL != model_api)
-  {
-    GNUNET_break (NULL == GNUNET_PLUGIN_unload (model_lib_name, model_api));
-    GNUNET_free (model_lib_name);
-    model_lib_name = NULL;
-  }
-}
-
-
-/**
- * Sensor value watch callback
- *
- * @param cls Sensor model struct
- * @param record Received record from peerstore, should contain new sensor 
value
- * @param emsg Error message from peerstore if any, NULL if no errors
- * @return #GNUNET_YES
- */
-static int
-sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg)
-{
-  struct SensorModel *model = cls;
-  double *val;
-  int anomalous;
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Received a sensor value, will feed to sensor model.\n");
-  if (sizeof (double) != record->value_size)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Received an invalid sensor value."));
-    return GNUNET_YES;
-  }
-  val = (double *) (record->value);
-  anomalous = model_api->feed_model (model->cls, *val);
-  if (GNUNET_YES == anomalous)
-  {
-    model->positive_count++;
-    model->negative_count = 0;
-    if (GNUNET_NO == model->anomalous &&
-        model->positive_count >= confirmation_count)
-    {
-      model->anomalous = GNUNET_YES;
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-           "Anomaly state started for sensor `%s'.\n", model->sensor->name);
-      GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid,
-                              model->sensor->name, &model->anomalous,
-                              sizeof (model->anomalous),
-                              GNUNET_TIME_UNIT_FOREVER_ABS,
-                              GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, 
NULL);
-    }
-  }
-  else
-  {
-    model->negative_count++;
-    model->positive_count = 0;
-    if (GNUNET_YES == model->anomalous &&
-        model->negative_count >= confirmation_count)
-    {
-      model->anomalous = GNUNET_NO;
-      LOG (GNUNET_ERROR_TYPE_INFO, "Anomaly state stopped for sensor `%s'.\n",
-           model->sensor->name);
-      GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid,
-                              model->sensor->name, &model->anomalous,
-                              sizeof (model->anomalous),
-                              GNUNET_TIME_UNIT_FOREVER_ABS,
-                              GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, 
NULL);
-    }
-  }
-  return GNUNET_YES;
-}
-
-
-/**
- * Iterator for defined sensors
- * Creates sensor model for numeric sensors
- *
- * @param cls unused
- * @param key unused
- * @param value a 'struct GNUNET_SENSOR_SensorInfo *' with sensor information
- * @return #GNUNET_YES to continue iterations
- */
-static int
-init_sensor_model (void *cls, const struct GNUNET_HashCode *key, void *value)
-{
-  struct GNUNET_SENSOR_SensorInfo *sensor = value;
-  struct SensorModel *sensor_model;
-
-  if (0 != strcmp ("numeric", sensor->expected_datatype))
-    return GNUNET_YES;
-  sensor_model = GNUNET_new (struct SensorModel);
-  sensor_model->sensor = sensor;
-  sensor_model->wc =
-      GNUNET_PEERSTORE_watch (peerstore, "sensor", &peerid, sensor->name,
-                              &sensor_watcher, sensor_model);
-  sensor_model->anomalous = GNUNET_NO;
-  sensor_model->positive_count = 0;
-  sensor_model->negative_count = 0;
-  sensor_model->cls = model_api->create_model (model_api->cls);
-  GNUNET_CONTAINER_DLL_insert (models_head, models_tail, sensor_model);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Created sensor model for `%s'.\n",
-       sensor->name);
-  return GNUNET_YES;
-}
-
-
-/**
- * Start the sensor analysis module
- *
- * @param c our service configuration
- * @param sensors multihashmap of loaded sensors
- * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
- */
-int
-SENSOR_analysis_start (const struct GNUNET_CONFIGURATION_Handle *c,
-                       struct GNUNET_CONTAINER_MultiHashMap *sensors)
-{
-  char *model_name;
-
-  GNUNET_assert (NULL != sensors);
-  cfg = c;
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (cfg, "sensor-analysis", "MODEL",
-                                             &model_name))
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         _("Analysis model not defined in configuration.\n"));
-    return GNUNET_SYSERR;
-  }
-  GNUNET_asprintf (&model_lib_name, "libgnunet_plugin_sensor_model_%s",
-                   model_name);
-  model_api = GNUNET_PLUGIN_load (model_lib_name, (void *) cfg);
-  GNUNET_free (model_name);
-  if (NULL == model_api)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not load analysis model `%s'.\n"),
-         model_lib_name);
-    return GNUNET_SYSERR;
-  }
-  peerstore = GNUNET_PEERSTORE_connect (cfg);
-  if (NULL == peerstore)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         _("Could not connect to peerstore service.\n"));
-    SENSOR_analysis_stop ();
-    return GNUNET_SYSERR;
-  }
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, "sensor-analysis",
-                                             "CONFIRMATION_COUNT",
-                                             &confirmation_count))
-    confirmation_count = 1;
-  GNUNET_CRYPTO_get_peer_identity (cfg, &peerid);
-  GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_model, NULL);
-  return GNUNET_OK;
-}
-
-/* end of gnunet-service-sensor-analysis.c */

Deleted: gnunet/src/sensor/gnunet-service-sensor-reporting.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor-reporting.c 2014-08-04 18:05:05 UTC 
(rev 34109)
+++ gnunet/src/sensor/gnunet-service-sensor-reporting.c 2014-08-05 11:59:52 UTC 
(rev 34110)
@@ -1,578 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file sensor/gnunet-service-sensor-reporting.c
- * @brief sensor service reporting functionality
- * @author Omar Tarabai
- */
-#include <inttypes.h>
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "sensor.h"
-#include "gnunet_peerstore_service.h"
-#include "gnunet_cadet_service.h"
-#include "gnunet_applications.h"
-
-#define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting",__VA_ARGS__)
-
-/**
- * Retry interval (seconds) in case channel to collection point is busy
- */
-#define COLLECTION_RETRY 1
-
-/**
- * Context of reporting operations
- */
-struct ValueReportingContext
-{
-
-  /**
-   * DLL
-   */
-  struct ValueReportingContext *prev;
-
-  /**
-   * DLL
-   */
-  struct ValueReportingContext *next;
-
-  /**
-   * Sensor information
-   */
-  struct GNUNET_SENSOR_SensorInfo *sensor;
-
-  /**
-   * Collection point reporting task
-   * (or #GNUNET_SCHEDULER_NO_TASK)
-   */
-  GNUNET_SCHEDULER_TaskIdentifier cp_task;
-
-  /**
-   * Watcher of sensor values
-   */
-  struct GNUNET_PEERSTORE_WatchContext *wc;
-
-  /**
-   * Last value read from sensor
-   */
-  void *last_value;
-
-  /**
-   * Size of @e last_value
-   */
-  size_t last_value_size;
-
-  /**
-   * Timestamp of last value reading
-   */
-  uint64_t timestamp;
-
-};
-
-/**
- * Context of a created CADET channel
- */
-struct CadetChannelContext
-{
-
-  /**
-   * DLL
-   */
-  struct CadetChannelContext *prev;
-
-  /**
-   * DLL
-   */
-  struct CadetChannelContext *next;
-
-  /**
-   * Peer Id of
-   */
-  struct GNUNET_PeerIdentity pid;
-
-  /**
-   * CADET channel handle
-   */
-  struct GNUNET_CADET_Channel *c;
-
-  /**
-   * Are we sending data on this channel?
-   * #GNUNET_YES / #GNUNET_NO
-   */
-  int sending;
-
-  /**
-   * Pointer to a pending message to be sent over the channel
-   */
-  void *pending_msg;
-
-  /**
-   * Size of @e pending_msg
-   */
-  size_t pending_msg_size;
-
-  /**
-   * Handle to CADET tranmission request in case we are sending
-   * (sending == #GNUNET_YES)
-   */
-  struct GNUNET_CADET_TransmitHandle *th;
-
-  /**
-   * Are we currently destroying the channel and its context?
-   */
-  int destroying;
-
-};
-
-/**
- * Our configuration.
- */
-static const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-/**
- * Handle to peerstore service
- */
-static struct GNUNET_PEERSTORE_Handle *peerstore;
-
-/**
- * My peer id
- */
-static struct GNUNET_PeerIdentity mypeerid;
-
-/**
- * Handle to CADET service
- */
-static struct GNUNET_CADET_Handle *cadet;
-
-/**
- * Head of DLL of all reporting contexts
- */
-struct ValueReportingContext *vrc_head;
-
-/**
- * Tail of DLL of all reporting contexts
- */
-struct ValueReportingContext *vrc_tail;
-
-/**
- * Head of DLL of all cadet channels
- */
-struct CadetChannelContext *cc_head;
-
-/**
- * Tail of DLL of all cadet channels
- */
-struct CadetChannelContext *cc_tail;
-
-/**
- * Destroy a reporting context structure
- */
-static void
-destroy_reporting_context (struct ValueReportingContext *vrc)
-{
-  if (NULL != vrc->wc)
-  {
-    GNUNET_PEERSTORE_watch_cancel (vrc->wc);
-    vrc->wc = NULL;
-  }
-  if (GNUNET_SCHEDULER_NO_TASK != vrc->cp_task)
-  {
-    GNUNET_SCHEDULER_cancel (vrc->cp_task);
-    vrc->cp_task = GNUNET_SCHEDULER_NO_TASK;
-  }
-  if (NULL != vrc->last_value)
-  {
-    GNUNET_free (vrc->last_value);
-    vrc->last_value_size = 0;
-  }
-  GNUNET_free (vrc);
-}
-
-
-/**
- * Destroy a CADET channel context struct
- */
-static void
-destroy_cadet_channel_context (struct CadetChannelContext *cc)
-{
-  cc->destroying = GNUNET_YES;
-  if (NULL != cc->th)
-  {
-    GNUNET_CADET_notify_transmit_ready_cancel (cc->th);
-    cc->th = NULL;
-  }
-  if (NULL != cc->pending_msg)
-  {
-    GNUNET_free (cc->pending_msg);
-    cc->pending_msg = NULL;
-  }
-  if (NULL != cc->c)
-  {
-    GNUNET_CADET_channel_destroy (cc->c);
-    cc->c = NULL;
-  }
-  GNUNET_free (cc);
-}
-
-
-/**
- * Stop sensor reporting module
- */
-void
-SENSOR_reporting_stop ()
-{
-  struct ValueReportingContext *vrc;
-  struct CadetChannelContext *cc;
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor reporting module.\n");
-  while (NULL != cc_head)
-  {
-    cc = cc_head;
-    GNUNET_CONTAINER_DLL_remove (cc_head, cc_tail, cc);
-    destroy_cadet_channel_context (cc);
-  }
-  while (NULL != vrc_head)
-  {
-    vrc = vrc_head;
-    GNUNET_CONTAINER_DLL_remove (vrc_head, vrc_tail, vrc);
-    destroy_reporting_context (vrc);
-  }
-  if (NULL != peerstore)
-  {
-    GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
-    peerstore = NULL;
-  }
-  if (NULL != cadet)
-  {
-    GNUNET_CADET_disconnect (cadet);
-    cadet = NULL;
-  }
-}
-
-
-/**
- * Returns CADET channel established to given peer
- * or creates a new one
- *
- * @param pid Peer Identity
- * @return Context of established cadet channel
- */
-static struct CadetChannelContext *
-get_cadet_channel (struct GNUNET_PeerIdentity pid)
-{
-  struct CadetChannelContext *cc;
-
-  cc = cc_head;
-  while (NULL != cc)
-  {
-    if (0 == GNUNET_CRYPTO_cmp_peer_identity (&pid, &cc->pid))
-      return cc;
-    cc = cc->next;
-  }
-  cc = GNUNET_new (struct CadetChannelContext);
-  cc->c =
-      GNUNET_CADET_channel_create (cadet, cc, &pid,
-                                   GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
-                                   GNUNET_CADET_OPTION_DEFAULT);
-  cc->pid = pid;
-  cc->sending = GNUNET_NO;
-  cc->destroying = GNUNET_NO;
-  GNUNET_CONTAINER_DLL_insert (cc_head, cc_tail, cc);
-  return cc;
-}
-
-
-/**
- * Construct a reading message ready to be sent over CADET channel
- *
- * @param rc reporting context to read data from
- * @param msg used to return the created message structure
- * @return size of created message
- */
-static size_t
-construct_reading_message (struct ValueReportingContext *vrc,
-                           struct GNUNET_SENSOR_ReadingMessage **msg)
-{
-  struct GNUNET_SENSOR_ReadingMessage *ret;
-  uint16_t sensorname_size;
-  uint16_t total_size;
-  void *dummy;
-
-  sensorname_size = strlen (vrc->sensor->name) + 1;
-  total_size =
-      sizeof (struct GNUNET_SENSOR_ReadingMessage) + sensorname_size +
-      vrc->last_value_size;
-  ret = GNUNET_malloc (total_size);
-  ret->header.size = htons (total_size);
-  ret->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_READING);
-  ret->sensorname_size = htons (sensorname_size);
-  ret->sensorversion_major = htons (vrc->sensor->version_major);
-  ret->sensorversion_minor = htons (vrc->sensor->version_minor);
-  ret->timestamp = GNUNET_htobe64 (vrc->timestamp);
-  ret->value_size = htons (vrc->last_value_size);
-  dummy = &ret[1];
-  memcpy (dummy, vrc->sensor->name, sensorname_size);
-  dummy += sensorname_size;
-  memcpy (dummy, vrc->last_value, vrc->last_value_size);
-  *msg = ret;
-  return total_size;
-}
-
-
-/**
- * Function called to notify a client about the connection begin ready
- * to queue more data.  @a buf will be NULL and @a size zero if the
- * connection was closed for writing in the meantime.
- *
- * @param cls closure
- * @param size number of bytes available in @a buf
- * @param buf where the callee should write the message
- * @return number of bytes written to @a buf
- */
-static size_t
-do_report_collection_point (void *cls, size_t size, void *buf)
-{
-  struct CadetChannelContext *cc = cls;
-  size_t written = 0;
-
-  cc->th = NULL;
-  cc->sending = GNUNET_NO;
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Copying to CADET transmit buffer.\n");
-  if (NULL == buf)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "CADET failed to transmit message (NULL buf), discarding.\n");
-  }
-  else if (size < cc->pending_msg_size)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "CADET failed to transmit message (small size, expected: %u, got: %u)"
-         ", discarding.\n", cc->pending_msg_size, size);
-  }
-  else
-  {
-    memcpy (buf, cc->pending_msg, cc->pending_msg_size);
-    written = cc->pending_msg_size;
-  }
-  GNUNET_free (cc->pending_msg);
-  cc->pending_msg = NULL;
-  cc->pending_msg_size = 0;
-  return written;
-}
-
-
-/**
- * Task scheduled to send values to collection point
- *
- * @param cls closure, a `struct ValueReportingContext *`
- * @param tc unused
- */
-static void
-report_collection_point (void *cls,
-                         const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct ValueReportingContext *vrc = cls;
-  struct GNUNET_SENSOR_SensorInfo *sensor = vrc->sensor;
-  struct CadetChannelContext *cc;
-  struct GNUNET_SENSOR_ReadingMessage *msg;
-  size_t msg_size;
-
-  vrc->cp_task = GNUNET_SCHEDULER_NO_TASK;
-  if (0 == vrc->last_value_size) /* Did not receive a sensor value yet */
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Did not receive a value from `%s' to report yet.\n",
-         vrc->sensor->name);
-    vrc->cp_task =
-        GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval,
-                                      &report_collection_point, vrc);
-    return;
-  }
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Now trying to report last seen value of `%s' " "to collection 
point.\n",
-       vrc->sensor->name);
-  GNUNET_assert (NULL != sensor->collection_point);
-  cc = get_cadet_channel (*sensor->collection_point);
-  if (GNUNET_YES == cc->sending)
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Cadet channel to collection point busy, "
-         "trying again for sensor `%s' after %d seconds.\n", vrc->sensor->name,
-         COLLECTION_RETRY);
-    vrc->cp_task =
-        GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                      (GNUNET_TIME_UNIT_SECONDS,
-                                       COLLECTION_RETRY),
-                                      &report_collection_point, vrc);
-    return;
-  }
-  msg_size = construct_reading_message (vrc, &msg);
-  cc->sending = GNUNET_YES;
-  cc->pending_msg = msg;
-  cc->pending_msg_size = msg_size;
-  cc->th =
-      GNUNET_CADET_notify_transmit_ready (cc->c, GNUNET_YES,
-                                          sensor->value_reporting_interval, 
msg_size,
-                                          &do_report_collection_point, cc);
-  vrc->cp_task =
-      GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval,
-                                    &report_collection_point, vrc);
-}
-
-
-/**
- * Sensor value watch callback
- */
-static int
-sensor_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg)
-{
-  struct ValueReportingContext *vrc = cls;
-
-  if (NULL != emsg)
-    return GNUNET_YES;
-  if (NULL != vrc->last_value)
-  {
-    GNUNET_free (vrc->last_value);
-    vrc->last_value_size = 0;
-  }
-  vrc->last_value = GNUNET_malloc (record->value_size);
-  memcpy (vrc->last_value, record->value, record->value_size);
-  vrc->last_value_size = record->value_size;
-  vrc->timestamp = GNUNET_TIME_absolute_get ().abs_value_us;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Received a sensor `%s' watch value at " "timestamp %" PRIu64
-       ", updating notification last_value.\n", vrc->sensor->name,
-       vrc->timestamp);
-  return GNUNET_YES;
-}
-
-
-/**
- * Iterator for defined sensors
- * Watches sensors for readings to report
- *
- * @param cls unused
- * @param key unused
- * @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)
-{
-  struct GNUNET_SENSOR_SensorInfo *sensor = value;
-  struct ValueReportingContext *vrc;
-
-  if (NULL == sensor->collection_point ||
-      (GNUNET_NO == sensor->report_values && GNUNET_NO == 
sensor->report_anomalies))
-    return GNUNET_YES;
-  vrc = GNUNET_new (struct ValueReportingContext);
-  vrc->sensor = sensor;
-  vrc->last_value = NULL;
-  vrc->last_value_size = 0;
-  vrc->wc =
-      GNUNET_PEERSTORE_watch (peerstore, "sensor", &mypeerid, sensor->name,
-                              &sensor_watch_cb, vrc);
-  if (NULL != sensor->collection_point)
-  {
-    LOG (GNUNET_ERROR_TYPE_INFO,
-         "Will start reporting sensor `%s' values to "
-         "collection point `%s' every %s.\n", sensor->name,
-         GNUNET_i2s_full (sensor->collection_point),
-         GNUNET_STRINGS_relative_time_to_string 
(sensor->value_reporting_interval,
-                                                 GNUNET_YES));
-    vrc->cp_task =
-        GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval,
-                                      &report_collection_point, vrc);
-  }
-  GNUNET_CONTAINER_DLL_insert (vrc_head, vrc_tail, vrc);
-  return GNUNET_YES;
-}
-
-
-/**
- * Function called whenever a channel is destroyed.  Should clean up
- * any associated state.
- *
- * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
- *
- * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end (henceforth invalid)
- * @param channel_ctx place where local state associated
- *                   with the channel is stored
- */
-static void
-cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel,
-                         void *channel_ctx)
-{
-  struct CadetChannelContext *cc = channel_ctx;
-
-  if (GNUNET_YES == cc->destroying)
-    return;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "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);
-}
-
-/**
- * Start the sensor reporting module
- *
- * @param c our service configuration
- * @param sensors multihashmap of loaded sensors
- * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
- */
-int
-SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c,
-                        struct GNUNET_CONTAINER_MultiHashMap *sensors)
-{
-  static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
-    {NULL, 0, 0}
-  };
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor reporting module.\n");
-  GNUNET_assert (NULL != sensors);
-  cfg = c;
-  peerstore = GNUNET_PEERSTORE_connect (cfg);
-  if (NULL == peerstore)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         _("Failed to connect to peerstore service.\n"));
-    SENSOR_reporting_stop ();
-    return GNUNET_SYSERR;
-  }
-  cadet =
-      GNUNET_CADET_connect (cfg, NULL, NULL, &cadet_channel_destroyed,
-                            cadet_handlers, NULL);
-  if (NULL == cadet)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CADET service.\n"));
-    SENSOR_reporting_stop ();
-    return GNUNET_SYSERR;
-  }
-  GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid);
-  GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, 
NULL);
-  return GNUNET_OK;
-}
-
-/* end of gnunet-service-sensor-reporting.c */

Deleted: gnunet/src/sensor/gnunet-service-sensor-update.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor-update.c    2014-08-04 18:05:05 UTC 
(rev 34109)
+++ gnunet/src/sensor/gnunet-service-sensor-update.c    2014-08-05 11:59:52 UTC 
(rev 34110)
@@ -1,788 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file sensor/gnunet-service-sensor-update.c
- * @brief sensor service update functionality
- * @author Omar Tarabai
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "sensor.h"
-#include "gnunet_cadet_service.h"
-#include "gnunet_sensor_model_plugin.h"
-#include "gnunet_applications.h"
-
-#define LOG(kind,...) GNUNET_log_from (kind, "sensor-update",__VA_ARGS__)
-
-/**
- * Interval at which to contact update points for new sensor updates.
- */
-#define SENSOR_UPDATE_CHECK_INTERVAL GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_DAYS, 1)
-
-/**
- * Interval at which to retry contacting update point if we were busy.
- */
-#define SENSOR_UPDATE_CHECK_RETRY GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_HOURS, 1)
-
-
-/**
- * Message queued to be sent to an update point stored in a DLL
- */
-struct PendingMessage
-{
-
-  /**
-   * DLL
-   */
-  struct PendingMessage *prev;
-
-  /**
-   * DLL
-   */
-  struct PendingMessage *next;
-
-  /**
-   * Actual queued message
-   */
-  struct GNUNET_MessageHeader *msg;
-
-};
-
-/**
- * Sensors update point
- */
-struct UpdatePoint
-{
-
-  /**
-   * DLL
-   */
-  struct UpdatePoint *prev;
-
-  /**
-   * DLL
-   */
-  struct UpdatePoint *next;
-
-  /**
-   * Identity of peer running update point
-   */
-  struct GNUNET_PeerIdentity peer_id;
-
-  /**
-   * CADET channel to update point
-   */
-  struct GNUNET_CADET_Channel *ch;
-
-  /**
-   * CADET transmit handle for a message to be sent to update point.
-   */
-  struct GNUNET_CADET_TransmitHandle *th;
-
-  /**
-   * Head of DLL of pending requests to be sent to update point.
-   */
-  struct PendingMessage *pm_head;
-
-  /**
-   * Tail of DLL of pending requests to be sent to update point.
-   */
-  struct PendingMessage *pm_tail;
-
-  /**
-   * Are we waiting for a sensor list?
-   */
-  int expecting_sensor_list;
-
-  /**
-   * How many sensor updates did we request and are waiting for.
-   */
-  int expected_sensor_updates;
-
-  /**
-   * Did a failure occur while dealing with this update point before?
-   */
-  int failed;
-
-};
-
-
-/**
- * Our configuration.
- */
-static const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-/**
- * Hashmap of known sensors
- */
-static struct GNUNET_CONTAINER_MultiHashMap *sensors;
-
-/**
- * Head of update points DLL.
- */
-static struct UpdatePoint *up_head;
-
-/**
- * Tail of update points DLL.
- */
-static struct UpdatePoint *up_tail;
-
-/**
- * The current default update point to use.
- */
-static struct UpdatePoint *up_default;
-
-/**
- * Handle to CADET service
- */
-static struct GNUNET_CADET_Handle *cadet;
-
-/**
- * Are we in the process of checking and updating sensors?
- */
-static int updating;
-
-/**
- * GNUnet scheduler task that starts the update check process.
- */
-GNUNET_SCHEDULER_TaskIdentifier update_task;
-
-/**
- * Pointer to service reset function called when we have new sensor updates.
- */
-void (*reset_cb) ();
-
-
-/**
- * Contact update points to check for new updates
- *
- * @param cls unused
- * @param tc GNUnet scheduler task context
- */
-static void
-check_for_updates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Trigger sending next pending message to the default update point if any.
- *
- */
-static void
-trigger_send_next_msg ();
-
-
-/**
- * Cleanup update point context. This does not destroy the struct itself.
- *
- * @param up UpdatePoint struct
- */
-static void
-cleanup_updatepoint (struct UpdatePoint *up)
-{
-  struct PendingMessage *pm;
-
-  up->expecting_sensor_list = GNUNET_NO;
-  up->expected_sensor_updates = 0;
-  if (NULL != up->th)
-  {
-    GNUNET_CADET_notify_transmit_ready_cancel (up->th);
-    up->th = NULL;
-  }
-  pm = up->pm_head;
-  while (NULL != pm)
-  {
-    GNUNET_CONTAINER_DLL_remove (up->pm_head, up->pm_tail, pm);
-    GNUNET_free (pm->msg);
-    GNUNET_free (pm);
-    pm = up->pm_head;
-  }
-  if (NULL != up->ch)
-  {
-    GNUNET_CADET_channel_destroy (up->ch);
-    up->ch = NULL;
-  }
-}
-
-
-/**
- * Stop the sensor update module.
- */
-void
-SENSOR_update_stop ()
-{
-  struct UpdatePoint *up;
-
-  up_default = NULL;
-  up = up_head;
-  if (GNUNET_SCHEDULER_NO_TASK != update_task)
-  {
-    GNUNET_SCHEDULER_cancel (update_task);
-    update_task = GNUNET_SCHEDULER_NO_TASK;
-  }
-  while (NULL != up)
-  {
-    GNUNET_CONTAINER_DLL_remove (up_head, up_tail, up);
-    cleanup_updatepoint (up);
-    GNUNET_free (up);
-    up = up_head;
-  }
-  if (NULL != cadet)
-  {
-    GNUNET_CADET_disconnect (cadet);
-    cadet = NULL;
-  }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor update module stopped.\n");
-}
-
-
-/**
- * A failure occured in connecting/retrieval/verification with current default
- * update point. This method will try to find another update point, do cleanup
- * and reschedule update check.
- */
-static void
-fail ()
-{
-  struct UpdatePoint *up;
-
-  cleanup_updatepoint (up_default);
-  if (up_default == up_tail)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "All defined update points failed. Will retry again in %s.\n",
-         GNUNET_STRINGS_relative_time_to_string (SENSOR_UPDATE_CHECK_INTERVAL,
-                                                 GNUNET_NO));
-    up = up_head;
-    while (NULL != up)
-    {
-      up->failed = GNUNET_NO;
-      up = up->next;
-    }
-    update_task =
-        GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL,
-                                      &check_for_updates, NULL);
-    return;
-  }
-  LOG (GNUNET_ERROR_TYPE_WARNING,
-       "Update point `%s' failed, trying next one now.\n",
-       GNUNET_i2s (&up_default->peer_id));
-  up_default = up_default->next;
-  update_task = GNUNET_SCHEDULER_add_now (&check_for_updates, NULL);
-}
-
-
-/**
- * Function called to notify a client about the connection begin ready
- * to queue more data.  @a buf will be NULL and @a size zero if the
- * connection was closed for writing in the meantime.
- *
- * Perform the actual sending of the message to update point.
- *
- * @param cls closure (unused)
- * @param size number of bytes available in @a buf
- * @param buf where the callee should write the message
- * @return number of bytes written to @a buf
- */
-static size_t
-do_send_msg (void *cls, size_t size, void *buf)
-{
-  struct PendingMessage *pm;
-  size_t msg_size;
-
-  up_default->th = NULL;
-  pm = up_default->pm_head;
-  msg_size = ntohs (pm->msg->size);
-  GNUNET_CONTAINER_DLL_remove (up_default->pm_head, up_default->pm_tail, pm);
-  if (NULL == buf || size < msg_size)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Error trying to send a message to update point `%s'.\n"),
-                GNUNET_i2s (&up_default->peer_id));
-    fail ();
-    return 0;
-  }
-  memcpy (buf, pm->msg, msg_size);
-  GNUNET_free (pm->msg);
-  GNUNET_free (pm);
-  trigger_send_next_msg ();
-  return msg_size;
-}
-
-
-/**
- * Trigger sending next pending message to the default update point if any.
- *
- */
-static void
-trigger_send_next_msg ()
-{
-  struct PendingMessage *pm;
-
-  if (NULL == up_default->pm_head)
-    return;
-  if (NULL != up_default->th)
-    return;
-  pm = up_default->pm_head;
-  up_default->th =
-      GNUNET_CADET_notify_transmit_ready (up_default->ch, GNUNET_YES,
-                                          GNUNET_TIME_UNIT_FOREVER_REL,
-                                          ntohs (pm->msg->size), &do_send_msg,
-                                          NULL);
-}
-
-
-/**
- * Add a message to the queue to be sent to the current default update point.
- *
- * @param msg Message to be queued
- */
-static void
-queue_msg (struct GNUNET_MessageHeader *msg)
-{
-  struct PendingMessage *pm;
-
-  pm = GNUNET_new (struct PendingMessage);
-
-  pm->msg = msg;
-  GNUNET_CONTAINER_DLL_insert_tail (up_default->pm_head, up_default->pm_tail,
-                                    pm);
-  trigger_send_next_msg ();
-}
-
-
-/**
- * Contact update points to check for new updates
- *
- * @param cls unused
- * @param tc GNUnet scheduler task context
- */
-static void
-check_for_updates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct GNUNET_MessageHeader *msg;
-  size_t msg_size;
-
-  update_task = GNUNET_SCHEDULER_NO_TASK;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-  if (GNUNET_YES == updating)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Update process still running and update interval already exhausted."
-         "Retrying in %s.\n",
-         GNUNET_STRINGS_relative_time_to_string (SENSOR_UPDATE_CHECK_RETRY,
-                                                 GNUNET_NO));
-    update_task =
-        GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_RETRY,
-                                      &check_for_updates, NULL);
-    return;
-  }
-  updating = GNUNET_YES;
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking for sensor updates.\n");
-  GNUNET_assert (NULL != up_default);
-  up_default->ch =
-      GNUNET_CADET_channel_create (cadet, up_default, &up_default->peer_id,
-                                   GNUNET_APPLICATION_TYPE_SENSORUPDATE,
-                                   GNUNET_CADET_OPTION_DEFAULT);
-  if (NULL == up_default->ch)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         _("Failed to connect to update point `%s'.\n"),
-         GNUNET_i2s (&up_default->peer_id));
-    fail ();
-    return;
-  }
-  /* Start by requesting list of sensors available from update point */
-  up_default->expecting_sensor_list = GNUNET_YES;
-  msg = GNUNET_new (struct GNUNET_MessageHeader);
-  msg_size = sizeof (struct GNUNET_MessageHeader);
-  msg->size = htons (msg_size);
-  msg->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ);
-  queue_msg (msg);
-  update_task =
-      GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL,
-                                    &check_for_updates, NULL);
-}
-
-
-/**
- * Function that reads and validates (correctness not connectivity) of 
available
- * sensor update points.
- *
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
- */
-static int
-load_update_points ()
-{
-  char *points_list;
-  int points_list_len;
-  int i;
-  int start;
-  int len;
-  struct GNUNET_CRYPTO_EddsaPublicKey public_key;
-  struct UpdatePoint *up;
-
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (cfg, "sensor", "UPDATE_POINTS",
-                                             &points_list))
-  {
-    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "sensor",
-                               "UPDATE_POINTS");
-    return GNUNET_SYSERR;
-  }
-  points_list_len = strlen (points_list) + 1;
-  for (i = 0; i < points_list_len; i++)
-  {
-    if (' ' == points_list[i])
-      continue;
-    start = i;
-    len = 0;
-    while (' ' != points_list[i] && '\0' != points_list[i])
-    {
-      len++;
-      i++;
-    }
-    if (GNUNET_OK !=
-        GNUNET_CRYPTO_eddsa_public_key_from_string (points_list + start, len,
-                                                    &public_key))
-    {
-      LOG (GNUNET_ERROR_TYPE_ERROR,
-           "Invalid EDDSA public key `%.*s' for update point.\n", len,
-           points_list + len);
-      continue;
-    }
-    up = GNUNET_new (struct UpdatePoint);
-
-    up->peer_id.public_key = public_key;
-    up->ch = NULL;
-    up->th = NULL;
-    up->expecting_sensor_list = GNUNET_NO;
-    up->expected_sensor_updates = 0;
-    up->failed = GNUNET_NO;
-    GNUNET_CONTAINER_DLL_insert (up_head, up_tail, up);
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Loaded update point `%s'.\n",
-         GNUNET_i2s_full (&up->peer_id));
-  }
-  GNUNET_free (points_list);
-  return (NULL == up_head) ? GNUNET_SYSERR : GNUNET_OK;
-}
-
-
-/**
- * Checks if the given sensor name and version (retrieved from an update point)
- * is new for us and we would like to install it. This is the case if we don't
- * have this sensor or we have an old version of it.
- *
- * @param sensorname Sensor name
- * @param sensorversion_major First part of version number
- * @param sensorversion_minor Second part of version number
- * @return #GNUNET_YES if we don't have this sensor
- *         #GNUNET_NO if we have it
- */
-static int
-update_required (char *sensorname, uint16_t sensorversion_major,
-                 uint16_t sensorversion_minor)
-{
-  struct GNUNET_HashCode key;
-  struct GNUNET_SENSOR_SensorInfo *local_sensor;
-
-  GNUNET_CRYPTO_hash (sensorname, strlen (sensorname) + 1, &key);
-  local_sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key);
-  if (NULL == local_sensor)
-    return GNUNET_YES;
-  if (GNUNET_SENSOR_version_compare
-      (local_sensor->version_major, local_sensor->version_minor,
-       sensorversion_major, sensorversion_minor) < 0)
-    return GNUNET_YES;
-  return GNUNET_NO;
-}
-
-
-/**
- * Handler of a sensor list message received from an update point.
- *
- * @param cls Closure (unused).
- * @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_sensor_brief (void *cls, struct GNUNET_CADET_Channel *channel,
-                     void **channel_ctx,
-                     const struct GNUNET_MessageHeader *message)
-{
-  struct GNUNET_SENSOR_SensorBriefMessage *sbm;
-  struct GNUNET_MessageHeader *pull_req;
-  uint16_t version_major;
-  uint16_t version_minor;
-  uint16_t msg_size;
-
-  GNUNET_assert (*channel_ctx == up_default);
-  if (GNUNET_YES != up_default->expecting_sensor_list)
-  {
-    GNUNET_break_op (0);
-    fail ();
-    return GNUNET_OK;
-  }
-  if (GNUNET_MESSAGE_TYPE_SENSOR_END == ntohs (message->type))
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Received end of sensor list msg. We already requested %d updates.\n",
-         up_default->expected_sensor_updates);
-    up_default->expecting_sensor_list = GNUNET_NO;
-    if (0 == up_default->expected_sensor_updates)
-    {
-      updating = GNUNET_NO;
-      cleanup_updatepoint (up_default);
-      return GNUNET_OK;
-    }
-  }
-  else
-  {
-    sbm = (struct GNUNET_SENSOR_SensorBriefMessage *) message;
-    version_major = ntohs (sbm->version_major);
-    version_minor = ntohs (sbm->version_minor);
-    if (GNUNET_YES ==
-        update_required ((char *) &sbm[1], version_major, version_minor))
-    {
-      LOG (GNUNET_ERROR_TYPE_INFO,
-           "Requesting sensor %s %d.%d from update point.\n", &sbm[1],
-           version_major, version_minor);
-      /* We duplicate the same msg received but change the type and send it
-       * back to update point to ask for full sensor information. */
-      msg_size = ntohs (message->size);
-      pull_req = GNUNET_malloc (msg_size);
-      memcpy (pull_req, message, msg_size);
-      pull_req->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ);
-      queue_msg (pull_req);
-      up_default->expected_sensor_updates++;
-    }
-  }
-  GNUNET_CADET_receive_done (channel);
-  return GNUNET_OK;
-}
-
-
-/**
- * Update local sensor definitions with a sensor retrieved from an update 
point.
- *
- * @param sensorname Sensor name
- * @param sensorfile Buffer containing the sensor definition file
- * @param sensorfile_size Size of @e sensorfile
- * @param scriptname Name of associated script file, NULL if no script
- * @param scriptfile Buffer containing the script file, NULL if no script
- * @param scriptfile_size Size of @e scriptfile, 0 if no script
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-static int
-update_sensor (char *sensorname, void *sensorfile, uint16_t sensorfile_size,
-               char *scriptname, void *scriptfile, uint16_t scriptfile_size)
-{
-  char *sensors_dir;
-  char *sensor_path;
-  char *script_path;
-
-  LOG (GNUNET_ERROR_TYPE_INFO,
-       "Received new sensor information:\n" "Name: %s\n"
-       "Sensor file size: %d\n" "Script name: %s\n" "Script file size: %d.\n",
-       sensorname, sensorfile_size, (NULL == scriptname) ? "None" : scriptname,
-       scriptfile_size);
-  sensors_dir = GNUNET_SENSOR_get_sensor_dir ();
-  GNUNET_asprintf (&sensor_path, "%s%s", sensors_dir, sensorname);
-  GNUNET_DISK_fn_write (sensor_path, sensorfile, sensorfile_size,
-                        GNUNET_DISK_PERM_USER_READ | 
GNUNET_DISK_PERM_GROUP_READ
-                        | GNUNET_DISK_PERM_OTHER_READ |
-                        GNUNET_DISK_PERM_USER_WRITE);
-  if (NULL != scriptname)
-  {
-    GNUNET_asprintf (&script_path, "%s-files%s%s", sensor_path,
-                     DIR_SEPARATOR_STR, scriptname);
-    GNUNET_DISK_fn_write (script_path, scriptfile, scriptfile_size,
-                          GNUNET_DISK_PERM_USER_READ |
-                          GNUNET_DISK_PERM_GROUP_READ |
-                          GNUNET_DISK_PERM_OTHER_READ |
-                          GNUNET_DISK_PERM_USER_WRITE |
-                          GNUNET_DISK_PERM_GROUP_WRITE |
-                          GNUNET_DISK_PERM_USER_EXEC |
-                          GNUNET_DISK_PERM_GROUP_EXEC);
-    GNUNET_free (script_path);
-  }
-  GNUNET_free (sensors_dir);
-  GNUNET_free (sensor_path);
-  return GNUNET_OK;
-}
-
-
-/**
- * Resets the service after we are done with an update.
- *
- * @param cls unused
- * @param tc unused
- */
-void
-reset (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  reset_cb ();
-}
-
-
-/**
- * Handler of a sensor list message received from an update point.
- *
- * @param cls Closure (unused).
- * @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_sensor_full (void *cls, struct GNUNET_CADET_Channel *channel,
-                    void **channel_ctx,
-                    const struct GNUNET_MessageHeader *message)
-{
-  struct GNUNET_SENSOR_SensorFullMessage *sfm;
-  uint16_t msg_size;
-  uint16_t sensorfile_size;
-  uint16_t scriptfile_size;
-  char *sensorname_ptr;
-  void *sensorfile_ptr;
-  char *scriptname_ptr;
-  void *scriptfile_ptr;
-
-  /* error check */
-  GNUNET_assert (*channel_ctx == up_default);
-  msg_size = ntohs (message->size);
-  if (up_default->expected_sensor_updates <= 0 ||
-      msg_size < sizeof (struct GNUNET_SENSOR_SensorFullMessage))
-  {
-    GNUNET_break_op (0);
-    fail ();
-    return GNUNET_OK;
-  }
-  /* parse received msg */
-  sfm = (struct GNUNET_SENSOR_SensorFullMessage *) message;
-  sensorname_ptr = (char *) &sfm[1];
-  sensorfile_ptr = sensorname_ptr + ntohs (sfm->sensorname_size);
-  sensorfile_size = ntohs (sfm->sensorfile_size);
-  scriptfile_size = ntohs (sfm->scriptfile_size);
-  if (scriptfile_size > 0)
-  {
-    scriptname_ptr = sensorfile_ptr + sensorfile_size;
-    scriptfile_ptr = scriptname_ptr + ntohs (sfm->scriptname_size);
-  }
-  else
-  {
-    scriptname_ptr = NULL;
-    scriptfile_ptr = NULL;
-  }
-  update_sensor ((char *) &sfm[1], sensorfile_ptr, sensorfile_size,
-                 scriptname_ptr, scriptfile_ptr, scriptfile_size);
-  up_default->expected_sensor_updates--;
-  if (0 == up_default->expected_sensor_updates)
-  {
-    updating = GNUNET_NO;
-    cleanup_updatepoint (up_default);
-    GNUNET_SCHEDULER_add_continuation (&reset, NULL, 0);
-  }
-  else
-    GNUNET_CADET_receive_done (channel);
-  return GNUNET_OK;
-}
-
-
-/**
- * Function called whenever a channel is destroyed.  Should clean up
- * any associated state.
- *
- * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
- *
- * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end (henceforth invalid)
- * @param channel_ctx place where local state associated
- *                   with the channel is stored
- */
-static void
-cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel,
-                         void *channel_ctx)
-{
-  struct UpdatePoint *up = channel_ctx;
-
-  up->ch = NULL;
-  if (GNUNET_YES == updating)
-  {
-    fail ();
-    return;
-  }
-  cleanup_updatepoint (up);
-}
-
-
-/**
- * Start the sensor update module
- *
- * @param c our service configuration
- * @param s multihashmap of loaded sensors
- * @param cb callback to reset service components when we have new updates
- * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
- */
-int
-SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c,
-                     struct GNUNET_CONTAINER_MultiHashMap *s, void (*cb) ())
-{
-  static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
-    {&handle_sensor_brief, GNUNET_MESSAGE_TYPE_SENSOR_BRIEF, 0},
-    {&handle_sensor_brief, GNUNET_MESSAGE_TYPE_SENSOR_END, 0},
-    {&handle_sensor_full, GNUNET_MESSAGE_TYPE_SENSOR_FULL, 0},
-    {NULL, 0, 0}
-  };
-
-  GNUNET_assert (NULL != s);
-  cfg = c;
-  sensors = s;
-  reset_cb = cb;
-  cadet =
-      GNUNET_CADET_connect (cfg, NULL, NULL, &cadet_channel_destroyed,
-                            cadet_handlers, NULL);
-  if (NULL == cadet)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CADET service.\n"));
-    SENSOR_update_stop ();
-    return GNUNET_SYSERR;
-  }
-  if (GNUNET_OK != load_update_points ())
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to load update points.\n");
-    SENSOR_update_stop ();
-    return GNUNET_SYSERR;
-  }
-  up_default = up_head;
-  updating = GNUNET_NO;
-  update_task =
-      GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL,
-                                    &check_for_updates, NULL);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor update module started.\n");
-  return GNUNET_OK;
-}
-
-/* end of gnunet-service-sensor-update.c */

Modified: gnunet/src/sensor/gnunet-service-sensor.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor.c   2014-08-04 18:05:05 UTC (rev 
34109)
+++ gnunet/src/sensor/gnunet-service-sensor.c   2014-08-05 11:59:52 UTC (rev 
34110)
@@ -43,22 +43,22 @@
 /**
  * Handle to statistics service
  */
-struct GNUNET_STATISTICS_Handle *statistics;
+static struct GNUNET_STATISTICS_Handle *statistics;
 
 /**
  * Handle to peerstore service
  */
-struct GNUNET_PEERSTORE_Handle *peerstore;
+static struct GNUNET_PEERSTORE_Handle *peerstore;
 
 /**
  * Service name
  */
-char *subsystem = "sensor";
+static char *subsystem = "sensor";
 
 /**
  * My peer id
  */
-struct GNUNET_PeerIdentity peerid;
+static struct GNUNET_PeerIdentity peerid;
 
 
 /**
@@ -96,8 +96,9 @@
 stop ()
 {
   SENSOR_update_stop ();
-  SENSOR_reporting_stop ();
   SENSOR_analysis_stop ();
+  SENSOR_reporting_value_stop ();
+  SENSOR_reporting_anomaly_stop ();
   GNUNET_SENSOR_destroy_sensors (sensors);
 }
 
@@ -612,8 +613,9 @@
 {
   sensors = GNUNET_SENSOR_load_all_sensors ();
   schedule_all_sensors ();
+  SENSOR_reporting_value_start (cfg, sensors);
+  SENSOR_reporting_anomaly_start (cfg, sensors);
   SENSOR_analysis_start (cfg, sensors);
-  SENSOR_reporting_start (cfg, sensors);
   SENSOR_update_start (cfg, sensors, &reset);
 }
 

Added: gnunet/src/sensor/gnunet-service-sensor_analysis.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor_analysis.c                          
(rev 0)
+++ gnunet/src/sensor/gnunet-service-sensor_analysis.c  2014-08-05 11:59:52 UTC 
(rev 34110)
@@ -0,0 +1,324 @@
+/*
+     This file is part of GNUnet.
+     (C)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file sensor/gnunet-service-sensor_analysis.c
+ * @brief sensor service analysis functionality
+ * @author Omar Tarabai
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "sensor.h"
+#include "gnunet_peerstore_service.h"
+#include "gnunet_sensor_model_plugin.h"
+
+#define LOG(kind,...) GNUNET_log_from (kind, "sensor-analysis",__VA_ARGS__)
+
+/**
+ * Carries information about the analysis model
+ * corresponding to one sensor
+ */
+struct SensorModel
+{
+
+  /**
+   * DLL
+   */
+  struct SensorModel *prev;
+
+  /**
+   * DLL
+   */
+  struct SensorModel *next;
+
+  /**
+   * Pointer to sensor info structure
+   */
+  struct GNUNET_SENSOR_SensorInfo *sensor;
+
+  /**
+   * Watcher of sensor values
+   */
+  struct GNUNET_PEERSTORE_WatchContext *wc;
+
+  /**
+   * State of sensor. #GNUNET_YES if anomalous, #GNUNET_NO otherwise.
+   */
+  int anomalous;
+
+  /**
+   * Number of anomalous readings (positive) received in a row.
+   */
+  int positive_count;
+
+  /**
+   * Number of non-anomalous (negative) readings received in a row.
+   */
+  int negative_count;
+
+  /**
+   * Closure for model plugin.
+   * Usually, the instance of the model created for this sensor.
+   */
+  void *cls;
+
+};
+
+/**
+ * Our configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/*
+ * Model library name
+ */
+static char *model_lib_name;
+
+/**
+ * Model handle
+ */
+static struct GNUNET_SENSOR_ModelFunctions *model_api;
+
+/**
+ * Handle to peerstore service
+ */
+static struct GNUNET_PEERSTORE_Handle *peerstore;
+
+/**
+ * Head of DLL of created models
+ */
+static struct SensorModel *models_head;
+
+/**
+ * Tail of DLL of created models
+ */
+static struct SensorModel *models_tail;
+
+/**
+ * My peer id
+ */
+struct GNUNET_PeerIdentity peerid;
+
+/**
+ * How many subsequent values required to flip anomaly label.
+ * E.g. After 3 subsequent anomaly reports, status change to anomalous.
+ */
+unsigned long long confirmation_count;
+
+/**
+ * Destroy a created model
+ */
+static void
+destroy_sensor_model (struct SensorModel *sensor_model)
+{
+  GNUNET_assert (NULL != sensor_model);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying sensor model for `%s'.\n",
+       sensor_model->sensor->name);
+  if (NULL != sensor_model->wc)
+  {
+    GNUNET_PEERSTORE_watch_cancel (sensor_model->wc);
+    sensor_model->wc = NULL;
+  }
+  if (NULL != sensor_model->cls)
+  {
+    model_api->destroy_model (sensor_model->cls);
+    sensor_model->cls = NULL;
+  }
+  GNUNET_free (sensor_model);
+  sensor_model = NULL;
+}
+
+
+/**
+ * Stop the sensor analysis module
+ */
+void
+SENSOR_analysis_stop ()
+{
+  struct SensorModel *sm;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor analysis module.\n");
+  while (NULL != models_head)
+  {
+    sm = models_head;
+    GNUNET_CONTAINER_DLL_remove (models_head, models_tail, sm);
+    destroy_sensor_model (sm);
+  }
+  if (NULL != peerstore)
+  {
+    GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
+    peerstore = NULL;
+  }
+  if (NULL != model_api)
+  {
+    GNUNET_break (NULL == GNUNET_PLUGIN_unload (model_lib_name, model_api));
+    GNUNET_free (model_lib_name);
+    model_lib_name = NULL;
+  }
+}
+
+
+/**
+ * Sensor value watch callback
+ *
+ * @param cls Sensor model struct
+ * @param record Received record from peerstore, should contain new sensor 
value
+ * @param emsg Error message from peerstore if any, NULL if no errors
+ * @return #GNUNET_YES
+ */
+static int
+sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg)
+{
+  struct SensorModel *model = cls;
+  double *val;
+  int anomalous;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Received a sensor value, will feed to sensor model.\n");
+  if (sizeof (double) != record->value_size)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, _("Received an invalid sensor value."));
+    return GNUNET_YES;
+  }
+  val = (double *) (record->value);
+  anomalous = model_api->feed_model (model->cls, *val);
+  if (GNUNET_YES == anomalous)
+  {
+    model->positive_count++;
+    model->negative_count = 0;
+    if (GNUNET_NO == model->anomalous &&
+        model->positive_count >= confirmation_count)
+    {
+      model->anomalous = GNUNET_YES;
+      LOG (GNUNET_ERROR_TYPE_WARNING,
+           "Anomaly state started for sensor `%s'.\n", model->sensor->name);
+      GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid,
+                              model->sensor->name, &model->anomalous,
+                              sizeof (model->anomalous),
+                              GNUNET_TIME_absolute_get (),
+                              GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, 
NULL);
+    }
+  }
+  else
+  {
+    model->negative_count++;
+    model->positive_count = 0;
+    if (GNUNET_YES == model->anomalous &&
+        model->negative_count >= confirmation_count)
+    {
+      model->anomalous = GNUNET_NO;
+      LOG (GNUNET_ERROR_TYPE_INFO, "Anomaly state stopped for sensor `%s'.\n",
+           model->sensor->name);
+      GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid,
+                              model->sensor->name, &model->anomalous,
+                              sizeof (model->anomalous),
+                              GNUNET_TIME_absolute_get (),
+                              GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, 
NULL);
+    }
+  }
+  return GNUNET_YES;
+}
+
+
+/**
+ * Iterator for defined sensors
+ * Creates sensor model for numeric sensors
+ *
+ * @param cls unused
+ * @param key unused
+ * @param value a 'struct GNUNET_SENSOR_SensorInfo *' with sensor information
+ * @return #GNUNET_YES to continue iterations
+ */
+static int
+init_sensor_model (void *cls, const struct GNUNET_HashCode *key, void *value)
+{
+  struct GNUNET_SENSOR_SensorInfo *sensor = value;
+  struct SensorModel *sensor_model;
+
+  if (0 != strcmp ("numeric", sensor->expected_datatype))
+    return GNUNET_YES;
+  sensor_model = GNUNET_new (struct SensorModel);
+  sensor_model->sensor = sensor;
+  sensor_model->wc =
+      GNUNET_PEERSTORE_watch (peerstore, "sensor", &peerid, sensor->name,
+                              &sensor_watcher, sensor_model);
+  sensor_model->anomalous = GNUNET_NO;
+  sensor_model->positive_count = 0;
+  sensor_model->negative_count = 0;
+  sensor_model->cls = model_api->create_model (model_api->cls);
+  GNUNET_CONTAINER_DLL_insert (models_head, models_tail, sensor_model);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Created sensor model for `%s'.\n",
+       sensor->name);
+  return GNUNET_YES;
+}
+
+
+/**
+ * Start the sensor analysis module
+ *
+ * @param c our service configuration
+ * @param sensors multihashmap of loaded sensors
+ * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
+ */
+int
+SENSOR_analysis_start (const struct GNUNET_CONFIGURATION_Handle *c,
+                       struct GNUNET_CONTAINER_MultiHashMap *sensors)
+{
+  char *model_name;
+
+  GNUNET_assert (NULL != sensors);
+  cfg = c;
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg, "sensor-analysis", "MODEL",
+                                             &model_name))
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _("Analysis model not defined in configuration.\n"));
+    return GNUNET_SYSERR;
+  }
+  GNUNET_asprintf (&model_lib_name, "libgnunet_plugin_sensor_model_%s",
+                   model_name);
+  model_api = GNUNET_PLUGIN_load (model_lib_name, (void *) cfg);
+  GNUNET_free (model_name);
+  if (NULL == model_api)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not load analysis model `%s'.\n"),
+         model_lib_name);
+    return GNUNET_SYSERR;
+  }
+  peerstore = GNUNET_PEERSTORE_connect (cfg);
+  if (NULL == peerstore)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _("Could not connect to peerstore service.\n"));
+    SENSOR_analysis_stop ();
+    return GNUNET_SYSERR;
+  }
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (cfg, "sensor-analysis",
+                                             "CONFIRMATION_COUNT",
+                                             &confirmation_count))
+    confirmation_count = 1;
+  GNUNET_CRYPTO_get_peer_identity (cfg, &peerid);
+  GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_model, NULL);
+  return GNUNET_OK;
+}
+
+/* end of gnunet-service-sensor_analysis.c */

Added: gnunet/src/sensor/gnunet-service-sensor_reporting_anomaly.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor_reporting_anomaly.c                 
        (rev 0)
+++ gnunet/src/sensor/gnunet-service-sensor_reporting_anomaly.c 2014-08-05 
11:59:52 UTC (rev 34110)
@@ -0,0 +1,302 @@
+/*
+     This file is part of GNUnet.
+     (C)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file sensor/gnunet-service-sensor_reporting_anomaly.c
+ * @brief sensor service anomaly reporting functionality
+ * @author Omar Tarabai
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "sensor.h"
+#include "gnunet_peerstore_service.h"
+#include "gnunet_core_service.h"
+
+#define LOG(kind,...) GNUNET_log_from (kind, 
"sensor-reporting-anomaly",__VA_ARGS__)
+
+struct AnomalyReportingContext
+{
+
+  /**
+   * DLL
+   */
+  struct AnomalyReportingContext *prev;
+
+  /**
+   * DLL
+   */
+  struct AnomalyReportingContext *next;
+
+  /**
+   * Sensor information
+   */
+  struct GNUNET_SENSOR_SensorInfo *sensor;
+
+};
+
+/**
+ * Context of a connection to a peer through CORE
+ */
+struct CorePeerContext
+{
+
+  /**
+   * DLL
+   */
+  struct CorePeerContext *prev;
+
+  /**
+   * DLL
+   */
+  struct CorePeerContext *next;
+
+  /**
+   * Peer identity of connected peer
+   */
+  struct GNUNET_PeerIdentity *peerid;
+
+};
+
+
+/**
+ * Our configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Handle to core service
+ */
+static struct GNUNET_CORE_Handle *core;
+
+/**
+ * My peer id
+ */
+static struct GNUNET_PeerIdentity mypeerid;
+
+/**
+ * Head of DLL of anomaly reporting contexts
+ */
+static struct AnomalyReportingContext *arc_head;
+
+/**
+ * Tail of DLL of anomaly reporting contexts
+ */
+static struct AnomalyReportingContext *arc_tail;
+
+/**
+ * Head of DLL of CORE peer contexts
+ */
+static struct CorePeerContext *cp_head;
+
+/**
+ * Tail of DLL of CORE peer contexts
+ */
+static struct CorePeerContext *cp_tail;
+
+
+/**
+ * Destroy anomaly reporting context struct
+ *
+ * @param arc struct to destroy
+ */
+static void
+destroy_anomaly_reporting_context (struct AnomalyReportingContext *arc)
+{
+  GNUNET_free (arc);
+}
+
+
+/**
+ * Stop sensor anomaly reporting module
+ */
+void
+SENSOR_reporting_anomaly_stop ()
+{
+  struct AnomalyReportingContext *arc;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor anomaly reporting module.\n");
+  //TODO: destroy core peer contexts
+  //TODO: destroy core connection
+  arc = arc_head;
+  while (NULL != arc)
+  {
+    GNUNET_CONTAINER_DLL_remove (arc_head, arc_tail, arc);
+    destroy_anomaly_reporting_context (arc);
+    arc = arc_head;
+  }
+}
+
+
+/**
+ * Iterator for defined sensors
+ * Watches sensors for anomaly status change to report
+ *
+ * @param cls unused
+ * @param key unused
+ * @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)
+{
+  struct GNUNET_SENSOR_SensorInfo *sensor = value;
+  struct AnomalyReportingContext *arc;
+
+  if (NULL == sensor->collection_point)
+    return GNUNET_YES;
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Reporting sensor `%s' anomalies to collection point `%s'.\n",
+       sensor->name, GNUNET_i2s_full (sensor->collection_point));
+  arc = GNUNET_new (struct AnomalyReportingContext);
+  arc->sensor = sensor;
+  GNUNET_CONTAINER_DLL_insert (arc_head, arc_tail, arc);
+  //TODO
+  return GNUNET_YES;
+}
+
+
+/**
+ * Function called after #GNUNET_CORE_connect has succeeded (or failed
+ * for good).  Note that the private key of the peer is intentionally
+ * not exposed here; if you need it, your process should try to read
+ * the private key file directly (which should work if you are
+ * authorized...).  Implementations of this function must not call
+ * #GNUNET_CORE_disconnect (other than by scheduling a new task to
+ * do this later).
+ *
+ * @param cls closure (unused)
+ * @param my_identity ID of this peer, NULL if we failed
+ */
+static void
+core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
+{
+  if (NULL == my_identity)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CORE service.\n"));
+    SENSOR_reporting_anomaly_stop ();
+    return;
+  }
+  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, my_identity))
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _("Peer identity received from CORE doesn't match ours.\n"));
+    SENSOR_reporting_anomaly_stop ();
+    return;
+  }
+}
+
+
+/**
+ * Method called whenever a given peer connects through CORE.
+ *
+ * @param cls closure (unused)
+ * @param peer peer identity this notification is about
+ */
+static void
+core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+  struct CorePeerContext *cp;
+
+  if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer))
+    return;
+  cp = GNUNET_new (struct CorePeerContext);
+  cp->peerid = (struct GNUNET_PeerIdentity *)peer;
+  GNUNET_CONTAINER_DLL_insert (cp_head, cp_tail, cp);
+  //TODO: report to peer your anomaly status
+}
+
+
+/**
+ * Method called whenever a CORE peer disconnects.
+ *
+ * @param cls closure (unused)
+ * @param peer peer identity this notification is about
+ */
+static void
+core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+  struct CorePeerContext *cp;
+
+  if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer))
+    return;
+  cp = cp_head;
+  while (NULL != cp)
+  {
+    if (peer == cp->peerid)
+    {
+      GNUNET_CONTAINER_DLL_remove (cp_head, cp_tail, cp);
+      //TODO: call peer context destroy function
+      return;
+    }
+  }
+  LOG (GNUNET_ERROR_TYPE_ERROR,
+       _("Received disconnect notification from CORE"
+         " for a peer we didn't know about.\n"));
+}
+
+
+/**
+ * An inbound message is received from a peer through CORE.
+ *
+ * @param cls closure (unused)
+ * @param peer the other peer involved
+ * @param message the actual message
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close connection to the peer (signal serious 
error)
+ */
+static int
+core_inbound_cb (void *cls,
+    const struct GNUNET_PeerIdentity *other,
+    const struct GNUNET_MessageHeader *message)
+{
+  //TODO
+  return GNUNET_OK;
+}
+
+
+/**
+ * Start the sensor anomaly reporting module
+ *
+ * @param c our service configuration
+ * @param sensors multihashmap of loaded sensors
+ * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
+ */
+int
+SENSOR_reporting_anomaly_start (const struct GNUNET_CONFIGURATION_Handle *c,
+                                struct GNUNET_CONTAINER_MultiHashMap *sensors)
+{
+  static struct GNUNET_CORE_MessageHandler core_handlers[] = {
+    {NULL, 0, 0}                //TODO
+  };
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor anomaly reporting module.\n");
+  GNUNET_assert (NULL != sensors);
+  cfg = c;
+  core =
+      GNUNET_CORE_connect (cfg, NULL, &core_startup_cb, core_connect_cb,
+                           &core_disconnect_cb, core_inbound_cb, GNUNET_NO,
+                           NULL, GNUNET_YES, core_handlers);
+  GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid);
+  GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, 
NULL);
+  return GNUNET_OK;
+}
+
+/* end of gnunet-service-sensor_reporting_anomaly.c */

Added: gnunet/src/sensor/gnunet-service-sensor_reporting_value.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor_reporting_value.c                   
        (rev 0)
+++ gnunet/src/sensor/gnunet-service-sensor_reporting_value.c   2014-08-05 
11:59:52 UTC (rev 34110)
@@ -0,0 +1,571 @@
+/*
+     This file is part of GNUnet.
+     (C)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file sensor/gnunet-service-sensor_reporting_value.c
+ * @brief sensor service value reporting functionality
+ * @author Omar Tarabai
+ */
+#include <inttypes.h>
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "sensor.h"
+#include "gnunet_peerstore_service.h"
+#include "gnunet_cadet_service.h"
+#include "gnunet_applications.h"
+
+#define LOG(kind,...) GNUNET_log_from (kind, 
"sensor-reporting-value",__VA_ARGS__)
+
+/**
+ * Retry interval (seconds) in case channel to collection point is busy
+ */
+#define COLLECTION_RETRY 1
+
+/**
+ * Context of reporting sensor values
+ */
+struct ValueReportingContext
+{
+
+  /**
+   * DLL
+   */
+  struct ValueReportingContext *prev;
+
+  /**
+   * DLL
+   */
+  struct ValueReportingContext *next;
+
+  /**
+   * Sensor information
+   */
+  struct GNUNET_SENSOR_SensorInfo *sensor;
+
+  /**
+   * Collection point reporting task
+   * (or #GNUNET_SCHEDULER_NO_TASK)
+   */
+  GNUNET_SCHEDULER_TaskIdentifier cp_task;
+
+  /**
+   * Watcher of sensor values
+   */
+  struct GNUNET_PEERSTORE_WatchContext *wc;
+
+  /**
+   * Last value read from sensor
+   */
+  void *last_value;
+
+  /**
+   * Size of @e last_value
+   */
+  size_t last_value_size;
+
+  /**
+   * Timestamp of last value reading
+   */
+  uint64_t timestamp;
+
+};
+
+/**
+ * Context of a created CADET channel
+ */
+struct CadetChannelContext
+{
+
+  /**
+   * DLL
+   */
+  struct CadetChannelContext *prev;
+
+  /**
+   * DLL
+   */
+  struct CadetChannelContext *next;
+
+  /**
+   * Peer Id of
+   */
+  struct GNUNET_PeerIdentity pid;
+
+  /**
+   * CADET channel handle
+   */
+  struct GNUNET_CADET_Channel *c;
+
+  /**
+   * Are we sending data on this channel?
+   * #GNUNET_YES / #GNUNET_NO
+   */
+  int sending;
+
+  /**
+   * Pointer to a pending message to be sent over the channel
+   */
+  void *pending_msg;
+
+  /**
+   * Size of @e pending_msg
+   */
+  size_t pending_msg_size;
+
+  /**
+   * Handle to CADET tranmission request in case we are sending
+   * (sending == #GNUNET_YES)
+   */
+  struct GNUNET_CADET_TransmitHandle *th;
+
+  /**
+   * Are we currently destroying the channel and its context?
+   */
+  int destroying;
+
+};
+
+/**
+ * Our configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Handle to peerstore service
+ */
+static struct GNUNET_PEERSTORE_Handle *peerstore;
+
+/**
+ * My peer id
+ */
+static struct GNUNET_PeerIdentity mypeerid;
+
+/**
+ * Handle to CADET service
+ */
+static struct GNUNET_CADET_Handle *cadet;
+
+/**
+ * Head of DLL of all reporting contexts
+ */
+struct ValueReportingContext *vrc_head;
+
+/**
+ * Tail of DLL of all reporting contexts
+ */
+struct ValueReportingContext *vrc_tail;
+
+/**
+ * Head of DLL of all cadet channels
+ */
+struct CadetChannelContext *cc_head;
+
+/**
+ * Tail of DLL of all cadet channels
+ */
+struct CadetChannelContext *cc_tail;
+
+/**
+ * Destroy a reporting context structure
+ */
+static void
+destroy_value_reporting_context (struct ValueReportingContext *vrc)
+{
+  if (NULL != vrc->wc)
+  {
+    GNUNET_PEERSTORE_watch_cancel (vrc->wc);
+    vrc->wc = NULL;
+  }
+  if (GNUNET_SCHEDULER_NO_TASK != vrc->cp_task)
+  {
+    GNUNET_SCHEDULER_cancel (vrc->cp_task);
+    vrc->cp_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+  if (NULL != vrc->last_value)
+  {
+    GNUNET_free (vrc->last_value);
+    vrc->last_value_size = 0;
+  }
+  GNUNET_free (vrc);
+}
+
+
+/**
+ * Destroy a CADET channel context struct
+ */
+static void
+destroy_cadet_channel_context (struct CadetChannelContext *cc)
+{
+  cc->destroying = GNUNET_YES;
+  if (NULL != cc->th)
+  {
+    GNUNET_CADET_notify_transmit_ready_cancel (cc->th);
+    cc->th = NULL;
+  }
+  if (NULL != cc->pending_msg)
+  {
+    GNUNET_free (cc->pending_msg);
+    cc->pending_msg = NULL;
+  }
+  if (NULL != cc->c)
+  {
+    GNUNET_CADET_channel_destroy (cc->c);
+    cc->c = NULL;
+  }
+  GNUNET_free (cc);
+}
+
+
+/**
+ * Stop sensor value reporting module
+ */
+void
+SENSOR_reporting_value_stop ()
+{
+  struct ValueReportingContext *vrc;
+  struct CadetChannelContext *cc;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor value reporting module.\n");
+  while (NULL != cc_head)
+  {
+    cc = cc_head;
+    GNUNET_CONTAINER_DLL_remove (cc_head, cc_tail, cc);
+    destroy_cadet_channel_context (cc);
+  }
+  while (NULL != vrc_head)
+  {
+    vrc = vrc_head;
+    GNUNET_CONTAINER_DLL_remove (vrc_head, vrc_tail, vrc);
+    destroy_value_reporting_context (vrc);
+  }
+  if (NULL != peerstore)
+  {
+    GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
+    peerstore = NULL;
+  }
+  if (NULL != cadet)
+  {
+    GNUNET_CADET_disconnect (cadet);
+    cadet = NULL;
+  }
+}
+
+
+/**
+ * Returns CADET channel established to given peer or creates a new one.
+ *
+ * @param pid Peer Identity
+ * @return Context of established cadet channel
+ */
+static struct CadetChannelContext *
+get_cadet_channel (struct GNUNET_PeerIdentity pid)
+{
+  struct CadetChannelContext *cc;
+
+  cc = cc_head;
+  while (NULL != cc)
+  {
+    if (0 == GNUNET_CRYPTO_cmp_peer_identity (&pid, &cc->pid))
+      return cc;
+    cc = cc->next;
+  }
+  cc = GNUNET_new (struct CadetChannelContext);
+  cc->c =
+      GNUNET_CADET_channel_create (cadet, cc, &pid,
+                                   GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
+                                   GNUNET_CADET_OPTION_DEFAULT);
+  cc->pid = pid;
+  cc->sending = GNUNET_NO;
+  cc->destroying = GNUNET_NO;
+  GNUNET_CONTAINER_DLL_insert (cc_head, cc_tail, cc);
+  return cc;
+}
+
+
+/**
+ * Construct a reading message ready to be sent over CADET channel
+ *
+ * @param rc reporting context to read data from
+ * @param msg used to return the created message structure
+ * @return size of created message
+ */
+static size_t
+construct_reading_message (struct ValueReportingContext *vrc,
+                           struct GNUNET_SENSOR_ReadingMessage **msg)
+{
+  struct GNUNET_SENSOR_ReadingMessage *ret;
+  uint16_t sensorname_size;
+  uint16_t total_size;
+  void *dummy;
+
+  sensorname_size = strlen (vrc->sensor->name) + 1;
+  total_size =
+      sizeof (struct GNUNET_SENSOR_ReadingMessage) + sensorname_size +
+      vrc->last_value_size;
+  ret = GNUNET_malloc (total_size);
+  ret->header.size = htons (total_size);
+  ret->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_READING);
+  ret->sensorname_size = htons (sensorname_size);
+  ret->sensorversion_major = htons (vrc->sensor->version_major);
+  ret->sensorversion_minor = htons (vrc->sensor->version_minor);
+  ret->timestamp = GNUNET_htobe64 (vrc->timestamp);
+  ret->value_size = htons (vrc->last_value_size);
+  dummy = &ret[1];
+  memcpy (dummy, vrc->sensor->name, sensorname_size);
+  dummy += sensorname_size;
+  memcpy (dummy, vrc->last_value, vrc->last_value_size);
+  *msg = ret;
+  return total_size;
+}
+
+
+/**
+ * Function called to notify a client about the connection begin ready
+ * to queue more data.  @a buf will be NULL and @a size zero if the
+ * connection was closed for writing in the meantime.
+ *
+ * @param cls closure
+ * @param size number of bytes available in @a buf
+ * @param buf where the callee should write the message
+ * @return number of bytes written to @a buf
+ */
+static size_t
+do_report_value (void *cls, size_t size, void *buf)
+{
+  struct CadetChannelContext *cc = cls;
+  size_t written = 0;
+
+  cc->th = NULL;
+  cc->sending = GNUNET_NO;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Copying to CADET transmit buffer.\n");
+  if (NULL == buf)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "CADET failed to transmit message (NULL buf), discarding.\n");
+  }
+  else if (size < cc->pending_msg_size)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "CADET failed to transmit message (small size, expected: %u, got: %u)"
+         ", discarding.\n", cc->pending_msg_size, size);
+  }
+  else
+  {
+    memcpy (buf, cc->pending_msg, cc->pending_msg_size);
+    written = cc->pending_msg_size;
+  }
+  GNUNET_free (cc->pending_msg);
+  cc->pending_msg = NULL;
+  cc->pending_msg_size = 0;
+  return written;
+}
+
+
+/**
+ * Task scheduled to send values to collection point
+ *
+ * @param cls closure, a `struct ValueReportingContext *`
+ * @param tc unused
+ */
+static void
+report_value (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct ValueReportingContext *vrc = cls;
+  struct GNUNET_SENSOR_SensorInfo *sensor = vrc->sensor;
+  struct CadetChannelContext *cc;
+  struct GNUNET_SENSOR_ReadingMessage *msg;
+  size_t msg_size;
+
+  vrc->cp_task = GNUNET_SCHEDULER_NO_TASK;
+  if (0 == vrc->last_value_size)        /* Did not receive a sensor value yet 
*/
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "Did not receive a value from `%s' to report yet.\n",
+         vrc->sensor->name);
+    vrc->cp_task =
+        GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval,
+                                      &report_value, vrc);
+    return;
+  }
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Now trying to report last seen value of `%s' " "to collection 
point.\n",
+       vrc->sensor->name);
+  GNUNET_assert (NULL != sensor->collection_point);
+  cc = get_cadet_channel (*sensor->collection_point);
+  if (GNUNET_YES == cc->sending)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Cadet channel to collection point busy, "
+         "trying again for sensor `%s' after %d seconds.\n", vrc->sensor->name,
+         COLLECTION_RETRY);
+    vrc->cp_task =
+        GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                      (GNUNET_TIME_UNIT_SECONDS,
+                                       COLLECTION_RETRY), &report_value, vrc);
+    return;
+  }
+  msg_size = construct_reading_message (vrc, &msg);
+  cc->sending = GNUNET_YES;
+  cc->pending_msg = msg;
+  cc->pending_msg_size = msg_size;
+  cc->th =
+      GNUNET_CADET_notify_transmit_ready (cc->c, GNUNET_YES,
+                                          sensor->value_reporting_interval,
+                                          msg_size, &do_report_value, cc);
+  vrc->cp_task =
+      GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval,
+                                    &report_value, vrc);
+}
+
+
+/**
+ * Sensor value watch callback
+ */
+static int
+value_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg)
+{
+  struct ValueReportingContext *vrc = cls;
+
+  if (NULL != emsg)
+    return GNUNET_YES;
+  if (NULL != vrc->last_value)
+  {
+    GNUNET_free (vrc->last_value);
+    vrc->last_value_size = 0;
+  }
+  vrc->last_value = GNUNET_malloc (record->value_size);
+  memcpy (vrc->last_value, record->value, record->value_size);
+  vrc->last_value_size = record->value_size;
+  vrc->timestamp = GNUNET_TIME_absolute_get ().abs_value_us;
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Received a sensor `%s' watch value at " "timestamp %" PRIu64
+       ", updating notification last_value.\n", vrc->sensor->name,
+       vrc->timestamp);
+  return GNUNET_YES;
+}
+
+
+/**
+ * Function called whenever a channel is destroyed.  Should clean up
+ * any associated state.
+ *
+ * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
+ *
+ * @param cls closure (set from #GNUNET_CADET_connect)
+ * @param channel connection to the other end (henceforth invalid)
+ * @param channel_ctx place where local state associated
+ *                   with the channel is stored
+ */
+static void
+cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel,
+                         void *channel_ctx)
+{
+  struct CadetChannelContext *cc = channel_ctx;
+
+  if (GNUNET_YES == cc->destroying)
+    return;
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "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);
+}
+
+
+/**
+ * Iterator for defined sensors
+ * Watches sensors for readings to report
+ *
+ * @param cls unused
+ * @param key unused
+ * @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)
+{
+  struct GNUNET_SENSOR_SensorInfo *sensor = value;
+  struct ValueReportingContext *vrc;
+
+  if (NULL == sensor->collection_point || GNUNET_NO == sensor->report_values)
+    return GNUNET_YES;
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Reporting sensor `%s' values to collection point `%s' every %s.\n",
+       sensor->name, GNUNET_i2s_full (sensor->collection_point),
+       GNUNET_STRINGS_relative_time_to_string 
(sensor->value_reporting_interval,
+                                               GNUNET_YES));
+  vrc = GNUNET_new (struct ValueReportingContext);
+  vrc->sensor = sensor;
+  vrc->last_value = NULL;
+  vrc->last_value_size = 0;
+  vrc->wc =
+      GNUNET_PEERSTORE_watch (peerstore, "sensor", &mypeerid, sensor->name,
+                              &value_watch_cb, vrc);
+  vrc->cp_task =
+      GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval,
+                                    &report_value, vrc);
+  GNUNET_CONTAINER_DLL_insert (vrc_head, vrc_tail, vrc);
+  return GNUNET_YES;
+}
+
+
+/**
+ * Start the sensor value reporting module
+ *
+ * @param c our service configuration
+ * @param sensors multihashmap of loaded sensors
+ * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
+ */
+int
+SENSOR_reporting_value_start (const struct GNUNET_CONFIGURATION_Handle *c,
+                              struct GNUNET_CONTAINER_MultiHashMap *sensors)
+{
+  static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
+    {NULL, 0, 0}
+  };
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor value reporting module.\n");
+  GNUNET_assert (NULL != sensors);
+  cfg = c;
+  peerstore = GNUNET_PEERSTORE_connect (cfg);
+  if (NULL == peerstore)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _("Failed to connect to peerstore service.\n"));
+    SENSOR_reporting_value_stop ();
+    return GNUNET_SYSERR;
+  }
+  cadet =
+      GNUNET_CADET_connect (cfg, NULL, NULL, &cadet_channel_destroyed,
+                            cadet_handlers, NULL);
+  if (NULL == cadet)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CADET service.\n"));
+    SENSOR_reporting_value_stop ();
+    return GNUNET_SYSERR;
+  }
+  GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid);
+  GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, 
NULL);
+  return GNUNET_OK;
+}
+
+/* end of gnunet-service-sensor_reporting_value.c */

Added: gnunet/src/sensor/gnunet-service-sensor_update.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor_update.c                            
(rev 0)
+++ gnunet/src/sensor/gnunet-service-sensor_update.c    2014-08-05 11:59:52 UTC 
(rev 34110)
@@ -0,0 +1,788 @@
+/*
+     This file is part of GNUnet.
+     (C)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file sensor/gnunet-service-sensor_update.c
+ * @brief sensor service update functionality
+ * @author Omar Tarabai
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "sensor.h"
+#include "gnunet_cadet_service.h"
+#include "gnunet_sensor_model_plugin.h"
+#include "gnunet_applications.h"
+
+#define LOG(kind,...) GNUNET_log_from (kind, "sensor-update",__VA_ARGS__)
+
+/**
+ * Interval at which to contact update points for new sensor updates.
+ */
+#define SENSOR_UPDATE_CHECK_INTERVAL GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_DAYS, 1)
+
+/**
+ * Interval at which to retry contacting update point if we were busy.
+ */
+#define SENSOR_UPDATE_CHECK_RETRY GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_HOURS, 1)
+
+
+/**
+ * Message queued to be sent to an update point stored in a DLL
+ */
+struct PendingMessage
+{
+
+  /**
+   * DLL
+   */
+  struct PendingMessage *prev;
+
+  /**
+   * DLL
+   */
+  struct PendingMessage *next;
+
+  /**
+   * Actual queued message
+   */
+  struct GNUNET_MessageHeader *msg;
+
+};
+
+/**
+ * Sensors update point
+ */
+struct UpdatePoint
+{
+
+  /**
+   * DLL
+   */
+  struct UpdatePoint *prev;
+
+  /**
+   * DLL
+   */
+  struct UpdatePoint *next;
+
+  /**
+   * Identity of peer running update point
+   */
+  struct GNUNET_PeerIdentity peer_id;
+
+  /**
+   * CADET channel to update point
+   */
+  struct GNUNET_CADET_Channel *ch;
+
+  /**
+   * CADET transmit handle for a message to be sent to update point.
+   */
+  struct GNUNET_CADET_TransmitHandle *th;
+
+  /**
+   * Head of DLL of pending requests to be sent to update point.
+   */
+  struct PendingMessage *pm_head;
+
+  /**
+   * Tail of DLL of pending requests to be sent to update point.
+   */
+  struct PendingMessage *pm_tail;
+
+  /**
+   * Are we waiting for a sensor list?
+   */
+  int expecting_sensor_list;
+
+  /**
+   * How many sensor updates did we request and are waiting for.
+   */
+  int expected_sensor_updates;
+
+  /**
+   * Did a failure occur while dealing with this update point before?
+   */
+  int failed;
+
+};
+
+
+/**
+ * Our configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Hashmap of known sensors
+ */
+static struct GNUNET_CONTAINER_MultiHashMap *sensors;
+
+/**
+ * Head of update points DLL.
+ */
+static struct UpdatePoint *up_head;
+
+/**
+ * Tail of update points DLL.
+ */
+static struct UpdatePoint *up_tail;
+
+/**
+ * The current default update point to use.
+ */
+static struct UpdatePoint *up_default;
+
+/**
+ * Handle to CADET service
+ */
+static struct GNUNET_CADET_Handle *cadet;
+
+/**
+ * Are we in the process of checking and updating sensors?
+ */
+static int updating;
+
+/**
+ * GNUnet scheduler task that starts the update check process.
+ */
+GNUNET_SCHEDULER_TaskIdentifier update_task;
+
+/**
+ * Pointer to service reset function called when we have new sensor updates.
+ */
+void (*reset_cb) ();
+
+
+/**
+ * Contact update points to check for new updates
+ *
+ * @param cls unused
+ * @param tc GNUnet scheduler task context
+ */
+static void
+check_for_updates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+/**
+ * Trigger sending next pending message to the default update point if any.
+ *
+ */
+static void
+trigger_send_next_msg ();
+
+
+/**
+ * Cleanup update point context. This does not destroy the struct itself.
+ *
+ * @param up UpdatePoint struct
+ */
+static void
+cleanup_updatepoint (struct UpdatePoint *up)
+{
+  struct PendingMessage *pm;
+
+  up->expecting_sensor_list = GNUNET_NO;
+  up->expected_sensor_updates = 0;
+  if (NULL != up->th)
+  {
+    GNUNET_CADET_notify_transmit_ready_cancel (up->th);
+    up->th = NULL;
+  }
+  pm = up->pm_head;
+  while (NULL != pm)
+  {
+    GNUNET_CONTAINER_DLL_remove (up->pm_head, up->pm_tail, pm);
+    GNUNET_free (pm->msg);
+    GNUNET_free (pm);
+    pm = up->pm_head;
+  }
+  if (NULL != up->ch)
+  {
+    GNUNET_CADET_channel_destroy (up->ch);
+    up->ch = NULL;
+  }
+}
+
+
+/**
+ * Stop the sensor update module.
+ */
+void
+SENSOR_update_stop ()
+{
+  struct UpdatePoint *up;
+
+  up_default = NULL;
+  up = up_head;
+  if (GNUNET_SCHEDULER_NO_TASK != update_task)
+  {
+    GNUNET_SCHEDULER_cancel (update_task);
+    update_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+  while (NULL != up)
+  {
+    GNUNET_CONTAINER_DLL_remove (up_head, up_tail, up);
+    cleanup_updatepoint (up);
+    GNUNET_free (up);
+    up = up_head;
+  }
+  if (NULL != cadet)
+  {
+    GNUNET_CADET_disconnect (cadet);
+    cadet = NULL;
+  }
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor update module stopped.\n");
+}
+
+
+/**
+ * A failure occured in connecting/retrieval/verification with current default
+ * update point. This method will try to find another update point, do cleanup
+ * and reschedule update check.
+ */
+static void
+fail ()
+{
+  struct UpdatePoint *up;
+
+  cleanup_updatepoint (up_default);
+  if (up_default == up_tail)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "All defined update points failed. Will retry again in %s.\n",
+         GNUNET_STRINGS_relative_time_to_string (SENSOR_UPDATE_CHECK_INTERVAL,
+                                                 GNUNET_NO));
+    up = up_head;
+    while (NULL != up)
+    {
+      up->failed = GNUNET_NO;
+      up = up->next;
+    }
+    update_task =
+        GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL,
+                                      &check_for_updates, NULL);
+    return;
+  }
+  LOG (GNUNET_ERROR_TYPE_WARNING,
+       "Update point `%s' failed, trying next one now.\n",
+       GNUNET_i2s (&up_default->peer_id));
+  up_default = up_default->next;
+  update_task = GNUNET_SCHEDULER_add_now (&check_for_updates, NULL);
+}
+
+
+/**
+ * Function called to notify a client about the connection begin ready
+ * to queue more data.  @a buf will be NULL and @a size zero if the
+ * connection was closed for writing in the meantime.
+ *
+ * Perform the actual sending of the message to update point.
+ *
+ * @param cls closure (unused)
+ * @param size number of bytes available in @a buf
+ * @param buf where the callee should write the message
+ * @return number of bytes written to @a buf
+ */
+static size_t
+do_send_msg (void *cls, size_t size, void *buf)
+{
+  struct PendingMessage *pm;
+  size_t msg_size;
+
+  up_default->th = NULL;
+  pm = up_default->pm_head;
+  msg_size = ntohs (pm->msg->size);
+  GNUNET_CONTAINER_DLL_remove (up_default->pm_head, up_default->pm_tail, pm);
+  if (NULL == buf || size < msg_size)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Error trying to send a message to update point `%s'.\n"),
+                GNUNET_i2s (&up_default->peer_id));
+    fail ();
+    return 0;
+  }
+  memcpy (buf, pm->msg, msg_size);
+  GNUNET_free (pm->msg);
+  GNUNET_free (pm);
+  trigger_send_next_msg ();
+  return msg_size;
+}
+
+
+/**
+ * Trigger sending next pending message to the default update point if any.
+ *
+ */
+static void
+trigger_send_next_msg ()
+{
+  struct PendingMessage *pm;
+
+  if (NULL == up_default->pm_head)
+    return;
+  if (NULL != up_default->th)
+    return;
+  pm = up_default->pm_head;
+  up_default->th =
+      GNUNET_CADET_notify_transmit_ready (up_default->ch, GNUNET_YES,
+                                          GNUNET_TIME_UNIT_FOREVER_REL,
+                                          ntohs (pm->msg->size), &do_send_msg,
+                                          NULL);
+}
+
+
+/**
+ * Add a message to the queue to be sent to the current default update point.
+ *
+ * @param msg Message to be queued
+ */
+static void
+queue_msg (struct GNUNET_MessageHeader *msg)
+{
+  struct PendingMessage *pm;
+
+  pm = GNUNET_new (struct PendingMessage);
+
+  pm->msg = msg;
+  GNUNET_CONTAINER_DLL_insert_tail (up_default->pm_head, up_default->pm_tail,
+                                    pm);
+  trigger_send_next_msg ();
+}
+
+
+/**
+ * Contact update points to check for new updates
+ *
+ * @param cls unused
+ * @param tc GNUnet scheduler task context
+ */
+static void
+check_for_updates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_MessageHeader *msg;
+  size_t msg_size;
+
+  update_task = GNUNET_SCHEDULER_NO_TASK;
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    return;
+  if (GNUNET_YES == updating)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "Update process still running and update interval already exhausted."
+         "Retrying in %s.\n",
+         GNUNET_STRINGS_relative_time_to_string (SENSOR_UPDATE_CHECK_RETRY,
+                                                 GNUNET_NO));
+    update_task =
+        GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_RETRY,
+                                      &check_for_updates, NULL);
+    return;
+  }
+  updating = GNUNET_YES;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking for sensor updates.\n");
+  GNUNET_assert (NULL != up_default);
+  up_default->ch =
+      GNUNET_CADET_channel_create (cadet, up_default, &up_default->peer_id,
+                                   GNUNET_APPLICATION_TYPE_SENSORUPDATE,
+                                   GNUNET_CADET_OPTION_DEFAULT);
+  if (NULL == up_default->ch)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _("Failed to connect to update point `%s'.\n"),
+         GNUNET_i2s (&up_default->peer_id));
+    fail ();
+    return;
+  }
+  /* Start by requesting list of sensors available from update point */
+  up_default->expecting_sensor_list = GNUNET_YES;
+  msg = GNUNET_new (struct GNUNET_MessageHeader);
+  msg_size = sizeof (struct GNUNET_MessageHeader);
+  msg->size = htons (msg_size);
+  msg->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ);
+  queue_msg (msg);
+  update_task =
+      GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL,
+                                    &check_for_updates, NULL);
+}
+
+
+/**
+ * Function that reads and validates (correctness not connectivity) of 
available
+ * sensor update points.
+ *
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+static int
+load_update_points ()
+{
+  char *points_list;
+  int points_list_len;
+  int i;
+  int start;
+  int len;
+  struct GNUNET_CRYPTO_EddsaPublicKey public_key;
+  struct UpdatePoint *up;
+
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg, "sensor", "UPDATE_POINTS",
+                                             &points_list))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "sensor",
+                               "UPDATE_POINTS");
+    return GNUNET_SYSERR;
+  }
+  points_list_len = strlen (points_list) + 1;
+  for (i = 0; i < points_list_len; i++)
+  {
+    if (' ' == points_list[i])
+      continue;
+    start = i;
+    len = 0;
+    while (' ' != points_list[i] && '\0' != points_list[i])
+    {
+      len++;
+      i++;
+    }
+    if (GNUNET_OK !=
+        GNUNET_CRYPTO_eddsa_public_key_from_string (points_list + start, len,
+                                                    &public_key))
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+           "Invalid EDDSA public key `%.*s' for update point.\n", len,
+           points_list + len);
+      continue;
+    }
+    up = GNUNET_new (struct UpdatePoint);
+
+    up->peer_id.public_key = public_key;
+    up->ch = NULL;
+    up->th = NULL;
+    up->expecting_sensor_list = GNUNET_NO;
+    up->expected_sensor_updates = 0;
+    up->failed = GNUNET_NO;
+    GNUNET_CONTAINER_DLL_insert (up_head, up_tail, up);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Loaded update point `%s'.\n",
+         GNUNET_i2s_full (&up->peer_id));
+  }
+  GNUNET_free (points_list);
+  return (NULL == up_head) ? GNUNET_SYSERR : GNUNET_OK;
+}
+
+
+/**
+ * Checks if the given sensor name and version (retrieved from an update point)
+ * is new for us and we would like to install it. This is the case if we don't
+ * have this sensor or we have an old version of it.
+ *
+ * @param sensorname Sensor name
+ * @param sensorversion_major First part of version number
+ * @param sensorversion_minor Second part of version number
+ * @return #GNUNET_YES if we don't have this sensor
+ *         #GNUNET_NO if we have it
+ */
+static int
+update_required (char *sensorname, uint16_t sensorversion_major,
+                 uint16_t sensorversion_minor)
+{
+  struct GNUNET_HashCode key;
+  struct GNUNET_SENSOR_SensorInfo *local_sensor;
+
+  GNUNET_CRYPTO_hash (sensorname, strlen (sensorname) + 1, &key);
+  local_sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key);
+  if (NULL == local_sensor)
+    return GNUNET_YES;
+  if (GNUNET_SENSOR_version_compare
+      (local_sensor->version_major, local_sensor->version_minor,
+       sensorversion_major, sensorversion_minor) < 0)
+    return GNUNET_YES;
+  return GNUNET_NO;
+}
+
+
+/**
+ * Handler of a sensor list message received from an update point.
+ *
+ * @param cls Closure (unused).
+ * @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_sensor_brief (void *cls, struct GNUNET_CADET_Channel *channel,
+                     void **channel_ctx,
+                     const struct GNUNET_MessageHeader *message)
+{
+  struct GNUNET_SENSOR_SensorBriefMessage *sbm;
+  struct GNUNET_MessageHeader *pull_req;
+  uint16_t version_major;
+  uint16_t version_minor;
+  uint16_t msg_size;
+
+  GNUNET_assert (*channel_ctx == up_default);
+  if (GNUNET_YES != up_default->expecting_sensor_list)
+  {
+    GNUNET_break_op (0);
+    fail ();
+    return GNUNET_OK;
+  }
+  if (GNUNET_MESSAGE_TYPE_SENSOR_END == ntohs (message->type))
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Received end of sensor list msg. We already requested %d updates.\n",
+         up_default->expected_sensor_updates);
+    up_default->expecting_sensor_list = GNUNET_NO;
+    if (0 == up_default->expected_sensor_updates)
+    {
+      updating = GNUNET_NO;
+      cleanup_updatepoint (up_default);
+      return GNUNET_OK;
+    }
+  }
+  else
+  {
+    sbm = (struct GNUNET_SENSOR_SensorBriefMessage *) message;
+    version_major = ntohs (sbm->version_major);
+    version_minor = ntohs (sbm->version_minor);
+    if (GNUNET_YES ==
+        update_required ((char *) &sbm[1], version_major, version_minor))
+    {
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           "Requesting sensor %s %d.%d from update point.\n", &sbm[1],
+           version_major, version_minor);
+      /* We duplicate the same msg received but change the type and send it
+       * back to update point to ask for full sensor information. */
+      msg_size = ntohs (message->size);
+      pull_req = GNUNET_malloc (msg_size);
+      memcpy (pull_req, message, msg_size);
+      pull_req->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ);
+      queue_msg (pull_req);
+      up_default->expected_sensor_updates++;
+    }
+  }
+  GNUNET_CADET_receive_done (channel);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Update local sensor definitions with a sensor retrieved from an update 
point.
+ *
+ * @param sensorname Sensor name
+ * @param sensorfile Buffer containing the sensor definition file
+ * @param sensorfile_size Size of @e sensorfile
+ * @param scriptname Name of associated script file, NULL if no script
+ * @param scriptfile Buffer containing the script file, NULL if no script
+ * @param scriptfile_size Size of @e scriptfile, 0 if no script
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+static int
+update_sensor (char *sensorname, void *sensorfile, uint16_t sensorfile_size,
+               char *scriptname, void *scriptfile, uint16_t scriptfile_size)
+{
+  char *sensors_dir;
+  char *sensor_path;
+  char *script_path;
+
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Received new sensor information:\n" "Name: %s\n"
+       "Sensor file size: %d\n" "Script name: %s\n" "Script file size: %d.\n",
+       sensorname, sensorfile_size, (NULL == scriptname) ? "None" : scriptname,
+       scriptfile_size);
+  sensors_dir = GNUNET_SENSOR_get_sensor_dir ();
+  GNUNET_asprintf (&sensor_path, "%s%s", sensors_dir, sensorname);
+  GNUNET_DISK_fn_write (sensor_path, sensorfile, sensorfile_size,
+                        GNUNET_DISK_PERM_USER_READ | 
GNUNET_DISK_PERM_GROUP_READ
+                        | GNUNET_DISK_PERM_OTHER_READ |
+                        GNUNET_DISK_PERM_USER_WRITE);
+  if (NULL != scriptname)
+  {
+    GNUNET_asprintf (&script_path, "%s-files%s%s", sensor_path,
+                     DIR_SEPARATOR_STR, scriptname);
+    GNUNET_DISK_fn_write (script_path, scriptfile, scriptfile_size,
+                          GNUNET_DISK_PERM_USER_READ |
+                          GNUNET_DISK_PERM_GROUP_READ |
+                          GNUNET_DISK_PERM_OTHER_READ |
+                          GNUNET_DISK_PERM_USER_WRITE |
+                          GNUNET_DISK_PERM_GROUP_WRITE |
+                          GNUNET_DISK_PERM_USER_EXEC |
+                          GNUNET_DISK_PERM_GROUP_EXEC);
+    GNUNET_free (script_path);
+  }
+  GNUNET_free (sensors_dir);
+  GNUNET_free (sensor_path);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Resets the service after we are done with an update.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+void
+reset (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  reset_cb ();
+}
+
+
+/**
+ * Handler of a sensor list message received from an update point.
+ *
+ * @param cls Closure (unused).
+ * @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_sensor_full (void *cls, struct GNUNET_CADET_Channel *channel,
+                    void **channel_ctx,
+                    const struct GNUNET_MessageHeader *message)
+{
+  struct GNUNET_SENSOR_SensorFullMessage *sfm;
+  uint16_t msg_size;
+  uint16_t sensorfile_size;
+  uint16_t scriptfile_size;
+  char *sensorname_ptr;
+  void *sensorfile_ptr;
+  char *scriptname_ptr;
+  void *scriptfile_ptr;
+
+  /* error check */
+  GNUNET_assert (*channel_ctx == up_default);
+  msg_size = ntohs (message->size);
+  if (up_default->expected_sensor_updates <= 0 ||
+      msg_size < sizeof (struct GNUNET_SENSOR_SensorFullMessage))
+  {
+    GNUNET_break_op (0);
+    fail ();
+    return GNUNET_OK;
+  }
+  /* parse received msg */
+  sfm = (struct GNUNET_SENSOR_SensorFullMessage *) message;
+  sensorname_ptr = (char *) &sfm[1];
+  sensorfile_ptr = sensorname_ptr + ntohs (sfm->sensorname_size);
+  sensorfile_size = ntohs (sfm->sensorfile_size);
+  scriptfile_size = ntohs (sfm->scriptfile_size);
+  if (scriptfile_size > 0)
+  {
+    scriptname_ptr = sensorfile_ptr + sensorfile_size;
+    scriptfile_ptr = scriptname_ptr + ntohs (sfm->scriptname_size);
+  }
+  else
+  {
+    scriptname_ptr = NULL;
+    scriptfile_ptr = NULL;
+  }
+  update_sensor ((char *) &sfm[1], sensorfile_ptr, sensorfile_size,
+                 scriptname_ptr, scriptfile_ptr, scriptfile_size);
+  up_default->expected_sensor_updates--;
+  if (0 == up_default->expected_sensor_updates)
+  {
+    updating = GNUNET_NO;
+    cleanup_updatepoint (up_default);
+    GNUNET_SCHEDULER_add_continuation (&reset, NULL, 0);
+  }
+  else
+    GNUNET_CADET_receive_done (channel);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Function called whenever a channel is destroyed.  Should clean up
+ * any associated state.
+ *
+ * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
+ *
+ * @param cls closure (set from #GNUNET_CADET_connect)
+ * @param channel connection to the other end (henceforth invalid)
+ * @param channel_ctx place where local state associated
+ *                   with the channel is stored
+ */
+static void
+cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel,
+                         void *channel_ctx)
+{
+  struct UpdatePoint *up = channel_ctx;
+
+  up->ch = NULL;
+  if (GNUNET_YES == updating)
+  {
+    fail ();
+    return;
+  }
+  cleanup_updatepoint (up);
+}
+
+
+/**
+ * Start the sensor update module
+ *
+ * @param c our service configuration
+ * @param s multihashmap of loaded sensors
+ * @param cb callback to reset service components when we have new updates
+ * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
+ */
+int
+SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c,
+                     struct GNUNET_CONTAINER_MultiHashMap *s, void (*cb) ())
+{
+  static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
+    {&handle_sensor_brief, GNUNET_MESSAGE_TYPE_SENSOR_BRIEF, 0},
+    {&handle_sensor_brief, GNUNET_MESSAGE_TYPE_SENSOR_END, 0},
+    {&handle_sensor_full, GNUNET_MESSAGE_TYPE_SENSOR_FULL, 0},
+    {NULL, 0, 0}
+  };
+
+  GNUNET_assert (NULL != s);
+  cfg = c;
+  sensors = s;
+  reset_cb = cb;
+  cadet =
+      GNUNET_CADET_connect (cfg, NULL, NULL, &cadet_channel_destroyed,
+                            cadet_handlers, NULL);
+  if (NULL == cadet)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CADET service.\n"));
+    SENSOR_update_stop ();
+    return GNUNET_SYSERR;
+  }
+  if (GNUNET_OK != load_update_points ())
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to load update points.\n");
+    SENSOR_update_stop ();
+    return GNUNET_SYSERR;
+  }
+  up_default = up_head;
+  updating = GNUNET_NO;
+  update_task =
+      GNUNET_SCHEDULER_add_delayed (SENSOR_UPDATE_CHECK_INTERVAL,
+                                    &check_for_updates, NULL);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor update module started.\n");
+  return GNUNET_OK;
+}
+
+/* end of gnunet-service-sensor_update.c */

Modified: gnunet/src/sensor/sensor.h
===================================================================
--- gnunet/src/sensor/sensor.h  2014-08-04 18:05:05 UTC (rev 34109)
+++ gnunet/src/sensor/sensor.h  2014-08-05 11:59:52 UTC (rev 34110)
@@ -81,25 +81,44 @@
 
 
 /**
- * Stop sensor reporting module
+ * Stop sensor value reporting module
  */
 void
-SENSOR_reporting_stop ();
+SENSOR_reporting_value_stop ();
 
 
 /**
- * Start the sensor reporting module
+ * Start the sensor value reporting module
  *
  * @param c our service configuration
  * @param sensors multihashmap of loaded sensors
  * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
  */
 int
-SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c,
-                        struct GNUNET_CONTAINER_MultiHashMap *sensors);
+SENSOR_reporting_value_start (const struct GNUNET_CONFIGURATION_Handle *c,
+                              struct GNUNET_CONTAINER_MultiHashMap *sensors);
 
 
 /**
+ * Stop sensor anomaly reporting module
+ */
+void
+SENSOR_reporting_anomaly_stop ();
+
+
+/**
+ * Start the sensor anomaly reporting module
+ *
+ * @param c our service configuration
+ * @param sensors multihashmap of loaded sensors
+ * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
+ */
+int
+SENSOR_reporting_anomaly_start (const struct GNUNET_CONFIGURATION_Handle *c,
+                                struct GNUNET_CONTAINER_MultiHashMap *sensors);
+
+
+/**
  * Stop the sensor update module
  */
 void




reply via email to

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