gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r33862 - in gnunet/src: peerstore sensor


From: gnunet
Subject: [GNUnet-SVN] r33862 - in gnunet/src: peerstore sensor
Date: Thu, 26 Jun 2014 14:25:04 +0200

Author: otarabai
Date: 2014-06-26 14:25:04 +0200 (Thu, 26 Jun 2014)
New Revision: 33862

Added:
   gnunet/src/sensor/plugin_sensor_model_gaussian.c
Modified:
   gnunet/src/peerstore/peerstore_api.c
   gnunet/src/sensor/Makefile.am
   gnunet/src/sensor/gnunet-service-sensor-analysis.c
   gnunet/src/sensor/gnunet-service-sensor.c
   gnunet/src/sensor/sensor.conf.in
   gnunet/src/sensor/sensor.h
Log:
Sensor gaussian model skeleton


Modified: gnunet/src/peerstore/peerstore_api.c
===================================================================
--- gnunet/src/peerstore/peerstore_api.c        2014-06-26 12:15:48 UTC (rev 
33861)
+++ gnunet/src/peerstore/peerstore_api.c        2014-06-26 12:25:04 UTC (rev 
33862)
@@ -799,6 +799,9 @@
   struct StoreKeyHashMessage *hm;
   struct GNUNET_PEERSTORE_WatchContext *wc;
 
+  GNUNET_assert(NULL != sub_system);
+  GNUNET_assert(NULL != peer);
+  GNUNET_assert(NULL != key);
   ev = GNUNET_MQ_msg(hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH);
   PEERSTORE_hash_key(sub_system, peer, key, &hm->keyhash);
   wc = GNUNET_new(struct GNUNET_PEERSTORE_WatchContext);

Modified: gnunet/src/sensor/Makefile.am
===================================================================
--- gnunet/src/sensor/Makefile.am       2014-06-26 12:15:48 UTC (rev 33861)
+++ gnunet/src/sensor/Makefile.am       2014-06-26 12:25:04 UTC (rev 33862)
@@ -4,6 +4,8 @@
 
 libexecdir= $(pkglibdir)/libexec/
 
+plugindir = $(libdir)/gnunet
+
 dist_pkgcfg_DATA = \
   sensor.conf
 
@@ -47,6 +49,21 @@
 libgnunetsensor_la_LDFLAGS = \
   $(GNUNET_LDFLAGS)
 
+plugin_LTLIBRARIES = \
+  libgnunet_plugin_sensor_model_gaussian.la
+  
+libgnunet_plugin_sensor_model_gaussian_la_SOURCES = \
+  plugin_sensor_model_gaussian.c
+libgnunet_plugin_sensor_model_gaussian_la_LIBADD = \
+  $(top_builddir)/src/sensor/libgnunetsensor.la  \
+  $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
+  $(LTLIBINTL)
+libgnunet_plugin_sensor_model_gaussian_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+libgnunet_plugin_sensor_model_gaussian_la_DEPENDENCIES = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  libgnunetsensor.la
+
 check_PROGRAMS = \
  test_sensor_api
 

Modified: gnunet/src/sensor/gnunet-service-sensor-analysis.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor-analysis.c  2014-06-26 12:15:48 UTC 
(rev 33861)
+++ gnunet/src/sensor/gnunet-service-sensor-analysis.c  2014-06-26 12:25:04 UTC 
(rev 33862)
@@ -84,28 +84,58 @@
  */
 static struct GNUNET_CONTAINER_MultiHashMap *sensor_models;
 
+/**
+ * My peer id
+ */
+struct GNUNET_PeerIdentity peerid;
+
 /*
  * TODO: document
  */
+static int
+destroy_sensor_model (void *cls,
+    const struct GNUNET_HashCode *key,
+    void *value)
+{
+  struct SensorModel *sensor_model = value;
+
+  if (NULL == sensor_model)
+    return GNUNET_YES;
+  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;
+  }
+  return GNUNET_YES;
+}
+
+/*
+ * Stop the sensor analysis module
+ */
 void SENSOR_analysis_stop()
 {
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor analysis module.\n");
   if (NULL != model)
   {
     GNUNET_break (NULL == GNUNET_PLUGIN_unload (model_lib_name, model));
     GNUNET_free (model_lib_name);
     model_lib_name = NULL;
   }
+  if (NULL != sensor_models)
+  {
+    GNUNET_CONTAINER_multihashmap_iterate(sensor_models, 
&destroy_sensor_model, NULL);
+    GNUNET_CONTAINER_multihashmap_destroy(sensor_models);
+    sensor_models = NULL;
+  }
   if (NULL != peerstore)
   {
     GNUNET_PEERSTORE_disconnect(peerstore);
     peerstore = NULL;
   }
-  if (NULL != sensor_models)
-  {
-    /* TODO: iterate over sensor models and destroy */
-    GNUNET_CONTAINER_multihashmap_destroy(sensor_models);
-    sensor_models = NULL;
-  }
 }
 
 /*
@@ -137,7 +167,7 @@
   is_numeric = GNUNET_NO;
   for (i = 0; NULL != analysis_datatypes[i]; i++)
   {
-    if (0 == strcasecmp (analysis_datatypes[i], sensor->expected_datatype))
+    if (0 == strcmp (analysis_datatypes[i], sensor->expected_datatype))
     {
       is_numeric = GNUNET_YES;
       break;
@@ -146,17 +176,22 @@
   if (GNUNET_NO == is_numeric)
     return GNUNET_YES;
   sensor_model = GNUNET_new(struct SensorModel);
+  sensor_model->sensor = sensor;
   sensor_model->wc = GNUNET_PEERSTORE_watch(peerstore,
-          "sensor", NULL, sensor->name,
+          "sensor", &peerid, sensor->name,
           &sensor_watcher, sensor_model);
   GNUNET_CONTAINER_multihashmap_put(sensor_models, key,
       sensor_model, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+      "Created sensor model for `%s'.\n", sensor->name);
   return GNUNET_YES;
 }
 
 /*
- * TODO: document
+ * Start the sensor analysis module
  *
+ * @param c our service configuration
+ * @param sensors_mhm multihashmap of loaded sensors
  * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
  */
 int
@@ -195,6 +230,7 @@
     SENSOR_analysis_stop();
     return GNUNET_SYSERR;
   }
+  GNUNET_CRYPTO_get_peer_identity(cfg, &peerid);
   sensor_models = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
   GNUNET_CONTAINER_multihashmap_iterate(sensors, &init_sensor_model, NULL);
 

Modified: gnunet/src/sensor/gnunet-service-sensor.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor.c   2014-06-26 12:15:48 UTC (rev 
33861)
+++ gnunet/src/sensor/gnunet-service-sensor.c   2014-06-26 12:25:04 UTC (rev 
33862)
@@ -159,6 +159,7 @@
 shutdown_task (void *cls,
               const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  SENSOR_analysis_stop();
   GNUNET_CONTAINER_multihashmap_iterate(sensors, &destroy_sensor, NULL);
   GNUNET_CONTAINER_multihashmap_destroy(sensors);
   if(NULL != statistics)
@@ -1000,6 +1001,7 @@
   sensors = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
   reload_sensors();
   schedule_all_sensors();
+  SENSOR_analysis_start(c, sensors);
   statistics = GNUNET_STATISTICS_create("sensor", cfg);
   GNUNET_CRYPTO_get_peer_identity(cfg, &peerid);
   peerstore = GNUNET_PEERSTORE_connect(cfg);

Added: gnunet/src/sensor/plugin_sensor_model_gaussian.c
===================================================================
--- gnunet/src/sensor/plugin_sensor_model_gaussian.c                            
(rev 0)
+++ gnunet/src/sensor/plugin_sensor_model_gaussian.c    2014-06-26 12:25:04 UTC 
(rev 33862)
@@ -0,0 +1,89 @@
+/*
+ * This file is part of GNUnet
+ * (C) 2013 Christian Grothoff (and other contributing authors)
+ *
+ * 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/plugin_sensor_model_gaussian.c
+ * @brief Gaussian model for sensor analysis
+ * @author Omar Tarabai
+ */
+
+#include "platform.h"
+#include "gnunet_sensor_model_plugin.h"
+#include "gnunet_sensor_service.h"
+#include "sensor.h"
+
+#define LOG(kind,...) GNUNET_log_from (kind, "sensor-model-gaussian", 
__VA_ARGS__)
+
+/*
+ * Plugin state information
+ */
+struct Plugin
+{
+
+  /*
+   * Configuration handle
+   */
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+};
+
+/*
+ * Entry point for the plugin.
+ *
+ * @param cls The struct GNUNET_CONFIGURATION_Handle.
+ * @return NULL on error, otherwise the plugin context
+ */
+void *
+libgnunet_plugin_sensor_model_gaussian_init (void *cls)
+{
+  static struct Plugin plugin;
+  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+  struct GNUNET_SENSOR_ModelFunctions *api;
+
+  if (NULL != plugin.cfg)
+    return NULL;                /* can only initialize once! */
+  memset (&plugin, 0, sizeof (struct Plugin));
+  plugin.cfg = cfg;
+  api = GNUNET_new (struct GNUNET_SENSOR_ModelFunctions);
+  api->cls = &plugin;
+  LOG(GNUNET_ERROR_TYPE_DEBUG, "Guassian model plugin is running\n");
+  return api;
+}
+
+/*
+ * Exit point from the plugin.
+ *
+ * @param cls The plugin context (as returned by "init")
+ * @return Always NULL
+ */
+void *
+libgnunet_plugin_sensor_model_gaussian_done (void *cls)
+{
+  struct GNUNET_SENSOR_ModelFunctions *api = cls;
+  struct Plugin *plugin = api->cls;
+
+  plugin->cfg = NULL;
+  GNUNET_free (api);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Guassian model plugin is finished\n");
+  return NULL;
+
+}
+
+/* end of plugin_sensor_model_gaussian.c */

Modified: gnunet/src/sensor/sensor.conf.in
===================================================================
--- gnunet/src/sensor/sensor.conf.in    2014-06-26 12:15:48 UTC (rev 33861)
+++ gnunet/src/sensor/sensor.conf.in    2014-06-26 12:25:04 UTC (rev 33862)
@@ -5,3 +5,5 @@
 # PORT = 2106
 @UNIXONLY@ PORT = 2087
 
+[sensor-analysis]
+model = gaussian
\ No newline at end of file

Modified: gnunet/src/sensor/sensor.h
===================================================================
--- gnunet/src/sensor/sensor.h  2014-06-26 12:15:48 UTC (rev 33861)
+++ gnunet/src/sensor/sensor.h  2014-06-26 12:25:04 UTC (rev 33862)
@@ -19,7 +19,7 @@
  */
 /**
  * @file sensor/sensor.h
- * @brief IPC messages
+ * @brief IPC messages and private service declarations
  * @author Omar Tarabai
  */
 
@@ -61,3 +61,19 @@
 };
 
 GNUNET_NETWORK_STRUCT_END
+
+/*
+ * Stop the sensor analysis module
+ */
+void SENSOR_analysis_stop();
+
+/*
+ * Start the sensor analysis module
+ *
+ * @param c our service configuration
+ * @param sensors_mhm 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_mhm);




reply via email to

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