aboutsummaryrefslogtreecommitdiff
path: root/src/sensor
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-06-26 12:25:04 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-06-26 12:25:04 +0000
commitd001d21fbd70b6f11bd52af98f7f89faf87ec429 (patch)
tree0210596953811c07674cf9197f22bb572180a483 /src/sensor
parentff6b4b8f32320a55827ef6c9c4237ba8fa3d1bd3 (diff)
downloadgnunet-d001d21fbd70b6f11bd52af98f7f89faf87ec429.tar.gz
gnunet-d001d21fbd70b6f11bd52af98f7f89faf87ec429.zip
Sensor gaussian model skeleton
Diffstat (limited to 'src/sensor')
-rw-r--r--src/sensor/Makefile.am17
-rw-r--r--src/sensor/gnunet-service-sensor-analysis.c54
-rw-r--r--src/sensor/gnunet-service-sensor.c2
-rw-r--r--src/sensor/plugin_sensor_model_gaussian.c89
-rw-r--r--src/sensor/sensor.conf.in2
-rw-r--r--src/sensor/sensor.h18
6 files changed, 172 insertions, 10 deletions
diff --git a/src/sensor/Makefile.am b/src/sensor/Makefile.am
index ca6760c29..a1c8881fa 100644
--- a/src/sensor/Makefile.am
+++ b/src/sensor/Makefile.am
@@ -4,6 +4,8 @@ pkgcfgdir= $(pkgdatadir)/config.d/
4 4
5libexecdir= $(pkglibdir)/libexec/ 5libexecdir= $(pkglibdir)/libexec/
6 6
7plugindir = $(libdir)/gnunet
8
7dist_pkgcfg_DATA = \ 9dist_pkgcfg_DATA = \
8 sensor.conf 10 sensor.conf
9 11
@@ -47,6 +49,21 @@ libgnunetsensor_la_LIBADD = \
47libgnunetsensor_la_LDFLAGS = \ 49libgnunetsensor_la_LDFLAGS = \
48 $(GNUNET_LDFLAGS) 50 $(GNUNET_LDFLAGS)
49 51
52plugin_LTLIBRARIES = \
53 libgnunet_plugin_sensor_model_gaussian.la
54
55libgnunet_plugin_sensor_model_gaussian_la_SOURCES = \
56 plugin_sensor_model_gaussian.c
57libgnunet_plugin_sensor_model_gaussian_la_LIBADD = \
58 $(top_builddir)/src/sensor/libgnunetsensor.la \
59 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
60 $(LTLIBINTL)
61libgnunet_plugin_sensor_model_gaussian_la_LDFLAGS = \
62 $(GN_PLUGIN_LDFLAGS)
63libgnunet_plugin_sensor_model_gaussian_la_DEPENDENCIES = \
64 $(top_builddir)/src/util/libgnunetutil.la \
65 libgnunetsensor.la
66
50check_PROGRAMS = \ 67check_PROGRAMS = \
51 test_sensor_api 68 test_sensor_api
52 69
diff --git a/src/sensor/gnunet-service-sensor-analysis.c b/src/sensor/gnunet-service-sensor-analysis.c
index 8ab486094..5a613559b 100644
--- a/src/sensor/gnunet-service-sensor-analysis.c
+++ b/src/sensor/gnunet-service-sensor-analysis.c
@@ -84,28 +84,58 @@ static const char *analysis_datatypes[] = { "uint64", "double", NULL };
84 */ 84 */
85static struct GNUNET_CONTAINER_MultiHashMap *sensor_models; 85static struct GNUNET_CONTAINER_MultiHashMap *sensor_models;
86 86
87/**
88 * My peer id
89 */
90struct GNUNET_PeerIdentity peerid;
91
87/* 92/*
88 * TODO: document 93 * TODO: document
89 */ 94 */
95static int
96destroy_sensor_model (void *cls,
97 const struct GNUNET_HashCode *key,
98 void *value)
99{
100 struct SensorModel *sensor_model = value;
101
102 if (NULL == sensor_model)
103 return GNUNET_YES;
104 LOG (GNUNET_ERROR_TYPE_DEBUG,
105 "Destroying sensor model for `%s'.\n",
106 sensor_model->sensor->name);
107 if (NULL != sensor_model->wc)
108 {
109 GNUNET_PEERSTORE_watch_cancel(sensor_model->wc);
110 sensor_model->wc = NULL;
111 }
112 return GNUNET_YES;
113}
114
115/*
116 * Stop the sensor analysis module
117 */
90void SENSOR_analysis_stop() 118void SENSOR_analysis_stop()
91{ 119{
120
121 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor analysis module.\n");
92 if (NULL != model) 122 if (NULL != model)
93 { 123 {
94 GNUNET_break (NULL == GNUNET_PLUGIN_unload (model_lib_name, model)); 124 GNUNET_break (NULL == GNUNET_PLUGIN_unload (model_lib_name, model));
95 GNUNET_free (model_lib_name); 125 GNUNET_free (model_lib_name);
96 model_lib_name = NULL; 126 model_lib_name = NULL;
97 } 127 }
98 if (NULL != peerstore)
99 {
100 GNUNET_PEERSTORE_disconnect(peerstore);
101 peerstore = NULL;
102 }
103 if (NULL != sensor_models) 128 if (NULL != sensor_models)
104 { 129 {
105 /* TODO: iterate over sensor models and destroy */ 130 GNUNET_CONTAINER_multihashmap_iterate(sensor_models, &destroy_sensor_model, NULL);
106 GNUNET_CONTAINER_multihashmap_destroy(sensor_models); 131 GNUNET_CONTAINER_multihashmap_destroy(sensor_models);
107 sensor_models = NULL; 132 sensor_models = NULL;
108 } 133 }
134 if (NULL != peerstore)
135 {
136 GNUNET_PEERSTORE_disconnect(peerstore);
137 peerstore = NULL;
138 }
109} 139}
110 140
111/* 141/*
@@ -137,7 +167,7 @@ init_sensor_model (void *cls,
137 is_numeric = GNUNET_NO; 167 is_numeric = GNUNET_NO;
138 for (i = 0; NULL != analysis_datatypes[i]; i++) 168 for (i = 0; NULL != analysis_datatypes[i]; i++)
139 { 169 {
140 if (0 == strcasecmp (analysis_datatypes[i], sensor->expected_datatype)) 170 if (0 == strcmp (analysis_datatypes[i], sensor->expected_datatype))
141 { 171 {
142 is_numeric = GNUNET_YES; 172 is_numeric = GNUNET_YES;
143 break; 173 break;
@@ -146,17 +176,22 @@ init_sensor_model (void *cls,
146 if (GNUNET_NO == is_numeric) 176 if (GNUNET_NO == is_numeric)
147 return GNUNET_YES; 177 return GNUNET_YES;
148 sensor_model = GNUNET_new(struct SensorModel); 178 sensor_model = GNUNET_new(struct SensorModel);
179 sensor_model->sensor = sensor;
149 sensor_model->wc = GNUNET_PEERSTORE_watch(peerstore, 180 sensor_model->wc = GNUNET_PEERSTORE_watch(peerstore,
150 "sensor", NULL, sensor->name, 181 "sensor", &peerid, sensor->name,
151 &sensor_watcher, sensor_model); 182 &sensor_watcher, sensor_model);
152 GNUNET_CONTAINER_multihashmap_put(sensor_models, key, 183 GNUNET_CONTAINER_multihashmap_put(sensor_models, key,
153 sensor_model, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 184 sensor_model, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
185 LOG (GNUNET_ERROR_TYPE_DEBUG,
186 "Created sensor model for `%s'.\n", sensor->name);
154 return GNUNET_YES; 187 return GNUNET_YES;
155} 188}
156 189
157/* 190/*
158 * TODO: document 191 * Start the sensor analysis module
159 * 192 *
193 * @param c our service configuration
194 * @param sensors_mhm multihashmap of loaded sensors
160 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise 195 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
161 */ 196 */
162int 197int
@@ -195,6 +230,7 @@ SENSOR_analysis_start(const struct GNUNET_CONFIGURATION_Handle *c,
195 SENSOR_analysis_stop(); 230 SENSOR_analysis_stop();
196 return GNUNET_SYSERR; 231 return GNUNET_SYSERR;
197 } 232 }
233 GNUNET_CRYPTO_get_peer_identity(cfg, &peerid);
198 sensor_models = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); 234 sensor_models = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
199 GNUNET_CONTAINER_multihashmap_iterate(sensors, &init_sensor_model, NULL); 235 GNUNET_CONTAINER_multihashmap_iterate(sensors, &init_sensor_model, NULL);
200 236
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c
index 96856c3bf..681f132b6 100644
--- a/src/sensor/gnunet-service-sensor.c
+++ b/src/sensor/gnunet-service-sensor.c
@@ -159,6 +159,7 @@ static void
159shutdown_task (void *cls, 159shutdown_task (void *cls,
160 const struct GNUNET_SCHEDULER_TaskContext *tc) 160 const struct GNUNET_SCHEDULER_TaskContext *tc)
161{ 161{
162 SENSOR_analysis_stop();
162 GNUNET_CONTAINER_multihashmap_iterate(sensors, &destroy_sensor, NULL); 163 GNUNET_CONTAINER_multihashmap_iterate(sensors, &destroy_sensor, NULL);
163 GNUNET_CONTAINER_multihashmap_destroy(sensors); 164 GNUNET_CONTAINER_multihashmap_destroy(sensors);
164 if(NULL != statistics) 165 if(NULL != statistics)
@@ -1000,6 +1001,7 @@ run (void *cls,
1000 sensors = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); 1001 sensors = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
1001 reload_sensors(); 1002 reload_sensors();
1002 schedule_all_sensors(); 1003 schedule_all_sensors();
1004 SENSOR_analysis_start(c, sensors);
1003 statistics = GNUNET_STATISTICS_create("sensor", cfg); 1005 statistics = GNUNET_STATISTICS_create("sensor", cfg);
1004 GNUNET_CRYPTO_get_peer_identity(cfg, &peerid); 1006 GNUNET_CRYPTO_get_peer_identity(cfg, &peerid);
1005 peerstore = GNUNET_PEERSTORE_connect(cfg); 1007 peerstore = GNUNET_PEERSTORE_connect(cfg);
diff --git a/src/sensor/plugin_sensor_model_gaussian.c b/src/sensor/plugin_sensor_model_gaussian.c
new file mode 100644
index 000000000..ee316035e
--- /dev/null
+++ b/src/sensor/plugin_sensor_model_gaussian.c
@@ -0,0 +1,89 @@
1/*
2 * This file is part of GNUnet
3 * (C) 2013 Christian Grothoff (and other contributing authors)
4 *
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
9 *
10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21/*
22 * @file sensor/plugin_sensor_model_gaussian.c
23 * @brief Gaussian model for sensor analysis
24 * @author Omar Tarabai
25 */
26
27#include "platform.h"
28#include "gnunet_sensor_model_plugin.h"
29#include "gnunet_sensor_service.h"
30#include "sensor.h"
31
32#define LOG(kind,...) GNUNET_log_from (kind, "sensor-model-gaussian", __VA_ARGS__)
33
34/*
35 * Plugin state information
36 */
37struct Plugin
38{
39
40 /*
41 * Configuration handle
42 */
43 const struct GNUNET_CONFIGURATION_Handle *cfg;
44
45};
46
47/*
48 * Entry point for the plugin.
49 *
50 * @param cls The struct GNUNET_CONFIGURATION_Handle.
51 * @return NULL on error, otherwise the plugin context
52 */
53void *
54libgnunet_plugin_sensor_model_gaussian_init (void *cls)
55{
56 static struct Plugin plugin;
57 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
58 struct GNUNET_SENSOR_ModelFunctions *api;
59
60 if (NULL != plugin.cfg)
61 return NULL; /* can only initialize once! */
62 memset (&plugin, 0, sizeof (struct Plugin));
63 plugin.cfg = cfg;
64 api = GNUNET_new (struct GNUNET_SENSOR_ModelFunctions);
65 api->cls = &plugin;
66 LOG(GNUNET_ERROR_TYPE_DEBUG, "Guassian model plugin is running\n");
67 return api;
68}
69
70/*
71 * Exit point from the plugin.
72 *
73 * @param cls The plugin context (as returned by "init")
74 * @return Always NULL
75 */
76void *
77libgnunet_plugin_sensor_model_gaussian_done (void *cls)
78{
79 struct GNUNET_SENSOR_ModelFunctions *api = cls;
80 struct Plugin *plugin = api->cls;
81
82 plugin->cfg = NULL;
83 GNUNET_free (api);
84 LOG (GNUNET_ERROR_TYPE_DEBUG, "Guassian model plugin is finished\n");
85 return NULL;
86
87}
88
89/* end of plugin_sensor_model_gaussian.c */
diff --git a/src/sensor/sensor.conf.in b/src/sensor/sensor.conf.in
index c1978ef8d..5c023d130 100644
--- a/src/sensor/sensor.conf.in
+++ b/src/sensor/sensor.conf.in
@@ -5,3 +5,5 @@ HOME = $SERVICEHOME
5# PORT = 2106 5# PORT = 2106
6@UNIXONLY@ PORT = 2087 6@UNIXONLY@ PORT = 2087
7 7
8[sensor-analysis]
9model = gaussian \ No newline at end of file
diff --git a/src/sensor/sensor.h b/src/sensor/sensor.h
index a505d47d3..0a301327d 100644
--- a/src/sensor/sensor.h
+++ b/src/sensor/sensor.h
@@ -19,7 +19,7 @@
19 */ 19 */
20/** 20/**
21 * @file sensor/sensor.h 21 * @file sensor/sensor.h
22 * @brief IPC messages 22 * @brief IPC messages and private service declarations
23 * @author Omar Tarabai 23 * @author Omar Tarabai
24 */ 24 */
25 25
@@ -61,3 +61,19 @@ struct SensorInfoMessage
61}; 61};
62 62
63GNUNET_NETWORK_STRUCT_END 63GNUNET_NETWORK_STRUCT_END
64
65/*
66 * Stop the sensor analysis module
67 */
68void SENSOR_analysis_stop();
69
70/*
71 * Start the sensor analysis module
72 *
73 * @param c our service configuration
74 * @param sensors_mhm multihashmap of loaded sensors
75 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
76 */
77int
78SENSOR_analysis_start(const struct GNUNET_CONFIGURATION_Handle *c,
79 struct GNUNET_CONTAINER_MultiHashMap *sensors_mhm);