diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-05 11:59:52 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-05 11:59:52 +0000 |
commit | 81e6e3f1dab7bfd3981b3cb72d18f3cc98a87906 (patch) | |
tree | b7485c715e6883d40a06d366f0165e907efd8bad /src/sensor | |
parent | 3384da8393563ad9a441df1b63b810a5bb68ce8e (diff) | |
download | gnunet-81e6e3f1dab7bfd3981b3cb72d18f3cc98a87906.tar.gz gnunet-81e6e3f1dab7bfd3981b3cb72d18f3cc98a87906.zip |
sensor: towards anomaly reporting
Diffstat (limited to 'src/sensor')
-rw-r--r-- | src/sensor/Makefile.am | 8 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor.c | 14 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_analysis.c (renamed from src/sensor/gnunet-service-sensor-analysis.c) | 8 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_reporting_anomaly.c | 302 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_reporting_value.c (renamed from src/sensor/gnunet-service-sensor-reporting.c) | 135 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_update.c (renamed from src/sensor/gnunet-service-sensor-update.c) | 4 | ||||
-rw-r--r-- | src/sensor/sensor.h | 29 |
7 files changed, 409 insertions, 91 deletions
diff --git a/src/sensor/Makefile.am b/src/sensor/Makefile.am index 70604208c..fb90513dd 100644 --- a/src/sensor/Makefile.am +++ b/src/sensor/Makefile.am | |||
@@ -36,15 +36,17 @@ gnunet_sensor_LDADD = \ | |||
36 | 36 | ||
37 | gnunet_service_sensor_SOURCES = \ | 37 | gnunet_service_sensor_SOURCES = \ |
38 | gnunet-service-sensor.c \ | 38 | gnunet-service-sensor.c \ |
39 | gnunet-service-sensor-analysis.c \ | 39 | gnunet-service-sensor_analysis.c \ |
40 | gnunet-service-sensor-reporting.c \ | 40 | gnunet-service-sensor_reporting_value.c \ |
41 | gnunet-service-sensor-update.c | 41 | gnunet-service-sensor_reporting_anomaly.c \ |
42 | gnunet-service-sensor_update.c | ||
42 | gnunet_service_sensor_LDADD = \ | 43 | gnunet_service_sensor_LDADD = \ |
43 | libgnunetsensorutil.la \ | 44 | libgnunetsensorutil.la \ |
44 | $(top_builddir)/src/util/libgnunetutil.la \ | 45 | $(top_builddir)/src/util/libgnunetutil.la \ |
45 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 46 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
46 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ | 47 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ |
47 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | 48 | $(top_builddir)/src/cadet/libgnunetcadet.la \ |
49 | $(top_builddir)/src/core/libgnunetcore.la \ | ||
48 | $(GN_LIBINTL) | 50 | $(GN_LIBINTL) |
49 | 51 | ||
50 | libgnunetsensor_la_SOURCES = \ | 52 | libgnunetsensor_la_SOURCES = \ |
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c index d9f3670d4..1df300410 100644 --- a/src/sensor/gnunet-service-sensor.c +++ b/src/sensor/gnunet-service-sensor.c | |||
@@ -43,22 +43,22 @@ static struct GNUNET_CONTAINER_MultiHashMap *sensors; | |||
43 | /** | 43 | /** |
44 | * Handle to statistics service | 44 | * Handle to statistics service |
45 | */ | 45 | */ |
46 | struct GNUNET_STATISTICS_Handle *statistics; | 46 | static struct GNUNET_STATISTICS_Handle *statistics; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Handle to peerstore service | 49 | * Handle to peerstore service |
50 | */ | 50 | */ |
51 | struct GNUNET_PEERSTORE_Handle *peerstore; | 51 | static struct GNUNET_PEERSTORE_Handle *peerstore; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Service name | 54 | * Service name |
55 | */ | 55 | */ |
56 | char *subsystem = "sensor"; | 56 | static char *subsystem = "sensor"; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * My peer id | 59 | * My peer id |
60 | */ | 60 | */ |
61 | struct GNUNET_PeerIdentity peerid; | 61 | static struct GNUNET_PeerIdentity peerid; |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
@@ -96,8 +96,9 @@ static void | |||
96 | stop () | 96 | stop () |
97 | { | 97 | { |
98 | SENSOR_update_stop (); | 98 | SENSOR_update_stop (); |
99 | SENSOR_reporting_stop (); | ||
100 | SENSOR_analysis_stop (); | 99 | SENSOR_analysis_stop (); |
100 | SENSOR_reporting_value_stop (); | ||
101 | SENSOR_reporting_anomaly_stop (); | ||
101 | GNUNET_SENSOR_destroy_sensors (sensors); | 102 | GNUNET_SENSOR_destroy_sensors (sensors); |
102 | } | 103 | } |
103 | 104 | ||
@@ -612,8 +613,9 @@ start () | |||
612 | { | 613 | { |
613 | sensors = GNUNET_SENSOR_load_all_sensors (); | 614 | sensors = GNUNET_SENSOR_load_all_sensors (); |
614 | schedule_all_sensors (); | 615 | schedule_all_sensors (); |
616 | SENSOR_reporting_value_start (cfg, sensors); | ||
617 | SENSOR_reporting_anomaly_start (cfg, sensors); | ||
615 | SENSOR_analysis_start (cfg, sensors); | 618 | SENSOR_analysis_start (cfg, sensors); |
616 | SENSOR_reporting_start (cfg, sensors); | ||
617 | SENSOR_update_start (cfg, sensors, &reset); | 619 | SENSOR_update_start (cfg, sensors, &reset); |
618 | } | 620 | } |
619 | 621 | ||
diff --git a/src/sensor/gnunet-service-sensor-analysis.c b/src/sensor/gnunet-service-sensor_analysis.c index 175fc259c..46422d039 100644 --- a/src/sensor/gnunet-service-sensor-analysis.c +++ b/src/sensor/gnunet-service-sensor_analysis.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file sensor/gnunet-service-sensor-analysis.c | 22 | * @file sensor/gnunet-service-sensor_analysis.c |
23 | * @brief sensor service analysis functionality | 23 | * @brief sensor service analysis functionality |
24 | * @author Omar Tarabai | 24 | * @author Omar Tarabai |
25 | */ | 25 | */ |
@@ -212,7 +212,7 @@ sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | |||
212 | GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid, | 212 | GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid, |
213 | model->sensor->name, &model->anomalous, | 213 | model->sensor->name, &model->anomalous, |
214 | sizeof (model->anomalous), | 214 | sizeof (model->anomalous), |
215 | GNUNET_TIME_UNIT_FOREVER_ABS, | 215 | GNUNET_TIME_absolute_get (), |
216 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); | 216 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); |
217 | } | 217 | } |
218 | } | 218 | } |
@@ -229,7 +229,7 @@ sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | |||
229 | GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid, | 229 | GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid, |
230 | model->sensor->name, &model->anomalous, | 230 | model->sensor->name, &model->anomalous, |
231 | sizeof (model->anomalous), | 231 | sizeof (model->anomalous), |
232 | GNUNET_TIME_UNIT_FOREVER_ABS, | 232 | GNUNET_TIME_absolute_get (), |
233 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); | 233 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); |
234 | } | 234 | } |
235 | } | 235 | } |
@@ -321,4 +321,4 @@ SENSOR_analysis_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
321 | return GNUNET_OK; | 321 | return GNUNET_OK; |
322 | } | 322 | } |
323 | 323 | ||
324 | /* end of gnunet-service-sensor-analysis.c */ | 324 | /* end of gnunet-service-sensor_analysis.c */ |
diff --git a/src/sensor/gnunet-service-sensor_reporting_anomaly.c b/src/sensor/gnunet-service-sensor_reporting_anomaly.c new file mode 100644 index 000000000..9a7a4eeb0 --- /dev/null +++ b/src/sensor/gnunet-service-sensor_reporting_anomaly.c | |||
@@ -0,0 +1,302 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) | ||
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/gnunet-service-sensor_reporting_anomaly.c | ||
23 | * @brief sensor service anomaly reporting functionality | ||
24 | * @author Omar Tarabai | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "sensor.h" | ||
29 | #include "gnunet_peerstore_service.h" | ||
30 | #include "gnunet_core_service.h" | ||
31 | |||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting-anomaly",__VA_ARGS__) | ||
33 | |||
34 | struct AnomalyReportingContext | ||
35 | { | ||
36 | |||
37 | /** | ||
38 | * DLL | ||
39 | */ | ||
40 | struct AnomalyReportingContext *prev; | ||
41 | |||
42 | /** | ||
43 | * DLL | ||
44 | */ | ||
45 | struct AnomalyReportingContext *next; | ||
46 | |||
47 | /** | ||
48 | * Sensor information | ||
49 | */ | ||
50 | struct GNUNET_SENSOR_SensorInfo *sensor; | ||
51 | |||
52 | }; | ||
53 | |||
54 | /** | ||
55 | * Context of a connection to a peer through CORE | ||
56 | */ | ||
57 | struct CorePeerContext | ||
58 | { | ||
59 | |||
60 | /** | ||
61 | * DLL | ||
62 | */ | ||
63 | struct CorePeerContext *prev; | ||
64 | |||
65 | /** | ||
66 | * DLL | ||
67 | */ | ||
68 | struct CorePeerContext *next; | ||
69 | |||
70 | /** | ||
71 | * Peer identity of connected peer | ||
72 | */ | ||
73 | struct GNUNET_PeerIdentity *peerid; | ||
74 | |||
75 | }; | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Our configuration. | ||
80 | */ | ||
81 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
82 | |||
83 | /** | ||
84 | * Handle to core service | ||
85 | */ | ||
86 | static struct GNUNET_CORE_Handle *core; | ||
87 | |||
88 | /** | ||
89 | * My peer id | ||
90 | */ | ||
91 | static struct GNUNET_PeerIdentity mypeerid; | ||
92 | |||
93 | /** | ||
94 | * Head of DLL of anomaly reporting contexts | ||
95 | */ | ||
96 | static struct AnomalyReportingContext *arc_head; | ||
97 | |||
98 | /** | ||
99 | * Tail of DLL of anomaly reporting contexts | ||
100 | */ | ||
101 | static struct AnomalyReportingContext *arc_tail; | ||
102 | |||
103 | /** | ||
104 | * Head of DLL of CORE peer contexts | ||
105 | */ | ||
106 | static struct CorePeerContext *cp_head; | ||
107 | |||
108 | /** | ||
109 | * Tail of DLL of CORE peer contexts | ||
110 | */ | ||
111 | static struct CorePeerContext *cp_tail; | ||
112 | |||
113 | |||
114 | /** | ||
115 | * Destroy anomaly reporting context struct | ||
116 | * | ||
117 | * @param arc struct to destroy | ||
118 | */ | ||
119 | static void | ||
120 | destroy_anomaly_reporting_context (struct AnomalyReportingContext *arc) | ||
121 | { | ||
122 | GNUNET_free (arc); | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Stop sensor anomaly reporting module | ||
128 | */ | ||
129 | void | ||
130 | SENSOR_reporting_anomaly_stop () | ||
131 | { | ||
132 | struct AnomalyReportingContext *arc; | ||
133 | |||
134 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor anomaly reporting module.\n"); | ||
135 | //TODO: destroy core peer contexts | ||
136 | //TODO: destroy core connection | ||
137 | arc = arc_head; | ||
138 | while (NULL != arc) | ||
139 | { | ||
140 | GNUNET_CONTAINER_DLL_remove (arc_head, arc_tail, arc); | ||
141 | destroy_anomaly_reporting_context (arc); | ||
142 | arc = arc_head; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | |||
147 | /** | ||
148 | * Iterator for defined sensors | ||
149 | * Watches sensors for anomaly status change to report | ||
150 | * | ||
151 | * @param cls unused | ||
152 | * @param key unused | ||
153 | * @param value a `struct GNUNET_SENSOR_SensorInfo *` with sensor information | ||
154 | * @return #GNUNET_YES to continue iterations | ||
155 | */ | ||
156 | static int | ||
157 | init_sensor_reporting (void *cls, const struct GNUNET_HashCode *key, | ||
158 | void *value) | ||
159 | { | ||
160 | struct GNUNET_SENSOR_SensorInfo *sensor = value; | ||
161 | struct AnomalyReportingContext *arc; | ||
162 | |||
163 | if (NULL == sensor->collection_point) | ||
164 | return GNUNET_YES; | ||
165 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
166 | "Reporting sensor `%s' anomalies to collection point `%s'.\n", | ||
167 | sensor->name, GNUNET_i2s_full (sensor->collection_point)); | ||
168 | arc = GNUNET_new (struct AnomalyReportingContext); | ||
169 | arc->sensor = sensor; | ||
170 | GNUNET_CONTAINER_DLL_insert (arc_head, arc_tail, arc); | ||
171 | //TODO | ||
172 | return GNUNET_YES; | ||
173 | } | ||
174 | |||
175 | |||
176 | /** | ||
177 | * Function called after #GNUNET_CORE_connect has succeeded (or failed | ||
178 | * for good). Note that the private key of the peer is intentionally | ||
179 | * not exposed here; if you need it, your process should try to read | ||
180 | * the private key file directly (which should work if you are | ||
181 | * authorized...). Implementations of this function must not call | ||
182 | * #GNUNET_CORE_disconnect (other than by scheduling a new task to | ||
183 | * do this later). | ||
184 | * | ||
185 | * @param cls closure (unused) | ||
186 | * @param my_identity ID of this peer, NULL if we failed | ||
187 | */ | ||
188 | static void | ||
189 | core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) | ||
190 | { | ||
191 | if (NULL == my_identity) | ||
192 | { | ||
193 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CORE service.\n")); | ||
194 | SENSOR_reporting_anomaly_stop (); | ||
195 | return; | ||
196 | } | ||
197 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, my_identity)) | ||
198 | { | ||
199 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
200 | _("Peer identity received from CORE doesn't match ours.\n")); | ||
201 | SENSOR_reporting_anomaly_stop (); | ||
202 | return; | ||
203 | } | ||
204 | } | ||
205 | |||
206 | |||
207 | /** | ||
208 | * Method called whenever a given peer connects through CORE. | ||
209 | * | ||
210 | * @param cls closure (unused) | ||
211 | * @param peer peer identity this notification is about | ||
212 | */ | ||
213 | static void | ||
214 | core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
215 | { | ||
216 | struct CorePeerContext *cp; | ||
217 | |||
218 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) | ||
219 | return; | ||
220 | cp = GNUNET_new (struct CorePeerContext); | ||
221 | cp->peerid = (struct GNUNET_PeerIdentity *)peer; | ||
222 | GNUNET_CONTAINER_DLL_insert (cp_head, cp_tail, cp); | ||
223 | //TODO: report to peer your anomaly status | ||
224 | } | ||
225 | |||
226 | |||
227 | /** | ||
228 | * Method called whenever a CORE peer disconnects. | ||
229 | * | ||
230 | * @param cls closure (unused) | ||
231 | * @param peer peer identity this notification is about | ||
232 | */ | ||
233 | static void | ||
234 | core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
235 | { | ||
236 | struct CorePeerContext *cp; | ||
237 | |||
238 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) | ||
239 | return; | ||
240 | cp = cp_head; | ||
241 | while (NULL != cp) | ||
242 | { | ||
243 | if (peer == cp->peerid) | ||
244 | { | ||
245 | GNUNET_CONTAINER_DLL_remove (cp_head, cp_tail, cp); | ||
246 | //TODO: call peer context destroy function | ||
247 | return; | ||
248 | } | ||
249 | } | ||
250 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
251 | _("Received disconnect notification from CORE" | ||
252 | " for a peer we didn't know about.\n")); | ||
253 | } | ||
254 | |||
255 | |||
256 | /** | ||
257 | * An inbound message is received from a peer through CORE. | ||
258 | * | ||
259 | * @param cls closure (unused) | ||
260 | * @param peer the other peer involved | ||
261 | * @param message the actual message | ||
262 | * @return #GNUNET_OK to keep the connection open, | ||
263 | * #GNUNET_SYSERR to close connection to the peer (signal serious error) | ||
264 | */ | ||
265 | static int | ||
266 | core_inbound_cb (void *cls, | ||
267 | const struct GNUNET_PeerIdentity *other, | ||
268 | const struct GNUNET_MessageHeader *message) | ||
269 | { | ||
270 | //TODO | ||
271 | return GNUNET_OK; | ||
272 | } | ||
273 | |||
274 | |||
275 | /** | ||
276 | * Start the sensor anomaly reporting module | ||
277 | * | ||
278 | * @param c our service configuration | ||
279 | * @param sensors multihashmap of loaded sensors | ||
280 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | ||
281 | */ | ||
282 | int | ||
283 | SENSOR_reporting_anomaly_start (const struct GNUNET_CONFIGURATION_Handle *c, | ||
284 | struct GNUNET_CONTAINER_MultiHashMap *sensors) | ||
285 | { | ||
286 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | ||
287 | {NULL, 0, 0} //TODO | ||
288 | }; | ||
289 | |||
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor anomaly reporting module.\n"); | ||
291 | GNUNET_assert (NULL != sensors); | ||
292 | cfg = c; | ||
293 | core = | ||
294 | GNUNET_CORE_connect (cfg, NULL, &core_startup_cb, core_connect_cb, | ||
295 | &core_disconnect_cb, core_inbound_cb, GNUNET_NO, | ||
296 | NULL, GNUNET_YES, core_handlers); | ||
297 | GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid); | ||
298 | GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, NULL); | ||
299 | return GNUNET_OK; | ||
300 | } | ||
301 | |||
302 | /* end of gnunet-service-sensor_reporting_anomaly.c */ | ||
diff --git a/src/sensor/gnunet-service-sensor-reporting.c b/src/sensor/gnunet-service-sensor_reporting_value.c index 9bcf9904b..84fbd11ae 100644 --- a/src/sensor/gnunet-service-sensor-reporting.c +++ b/src/sensor/gnunet-service-sensor_reporting_value.c | |||
@@ -19,8 +19,8 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file sensor/gnunet-service-sensor-reporting.c | 22 | * @file sensor/gnunet-service-sensor_reporting_value.c |
23 | * @brief sensor service reporting functionality | 23 | * @brief sensor service value reporting functionality |
24 | * @author Omar Tarabai | 24 | * @author Omar Tarabai |
25 | */ | 25 | */ |
26 | #include <inttypes.h> | 26 | #include <inttypes.h> |
@@ -31,7 +31,7 @@ | |||
31 | #include "gnunet_cadet_service.h" | 31 | #include "gnunet_cadet_service.h" |
32 | #include "gnunet_applications.h" | 32 | #include "gnunet_applications.h" |
33 | 33 | ||
34 | #define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting",__VA_ARGS__) | 34 | #define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting-value",__VA_ARGS__) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Retry interval (seconds) in case channel to collection point is busy | 37 | * Retry interval (seconds) in case channel to collection point is busy |
@@ -39,7 +39,7 @@ | |||
39 | #define COLLECTION_RETRY 1 | 39 | #define COLLECTION_RETRY 1 |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Context of reporting operations | 42 | * Context of reporting sensor values |
43 | */ | 43 | */ |
44 | struct ValueReportingContext | 44 | struct ValueReportingContext |
45 | { | 45 | { |
@@ -186,7 +186,7 @@ struct CadetChannelContext *cc_tail; | |||
186 | * Destroy a reporting context structure | 186 | * Destroy a reporting context structure |
187 | */ | 187 | */ |
188 | static void | 188 | static void |
189 | destroy_reporting_context (struct ValueReportingContext *vrc) | 189 | destroy_value_reporting_context (struct ValueReportingContext *vrc) |
190 | { | 190 | { |
191 | if (NULL != vrc->wc) | 191 | if (NULL != vrc->wc) |
192 | { | 192 | { |
@@ -234,15 +234,15 @@ destroy_cadet_channel_context (struct CadetChannelContext *cc) | |||
234 | 234 | ||
235 | 235 | ||
236 | /** | 236 | /** |
237 | * Stop sensor reporting module | 237 | * Stop sensor value reporting module |
238 | */ | 238 | */ |
239 | void | 239 | void |
240 | SENSOR_reporting_stop () | 240 | SENSOR_reporting_value_stop () |
241 | { | 241 | { |
242 | struct ValueReportingContext *vrc; | 242 | struct ValueReportingContext *vrc; |
243 | struct CadetChannelContext *cc; | 243 | struct CadetChannelContext *cc; |
244 | 244 | ||
245 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor reporting module.\n"); | 245 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor value reporting module.\n"); |
246 | while (NULL != cc_head) | 246 | while (NULL != cc_head) |
247 | { | 247 | { |
248 | cc = cc_head; | 248 | cc = cc_head; |
@@ -253,7 +253,7 @@ SENSOR_reporting_stop () | |||
253 | { | 253 | { |
254 | vrc = vrc_head; | 254 | vrc = vrc_head; |
255 | GNUNET_CONTAINER_DLL_remove (vrc_head, vrc_tail, vrc); | 255 | GNUNET_CONTAINER_DLL_remove (vrc_head, vrc_tail, vrc); |
256 | destroy_reporting_context (vrc); | 256 | destroy_value_reporting_context (vrc); |
257 | } | 257 | } |
258 | if (NULL != peerstore) | 258 | if (NULL != peerstore) |
259 | { | 259 | { |
@@ -269,8 +269,7 @@ SENSOR_reporting_stop () | |||
269 | 269 | ||
270 | 270 | ||
271 | /** | 271 | /** |
272 | * Returns CADET channel established to given peer | 272 | * Returns CADET channel established to given peer or creates a new one. |
273 | * or creates a new one | ||
274 | * | 273 | * |
275 | * @param pid Peer Identity | 274 | * @param pid Peer Identity |
276 | * @return Context of established cadet channel | 275 | * @return Context of established cadet channel |
@@ -348,7 +347,7 @@ construct_reading_message (struct ValueReportingContext *vrc, | |||
348 | * @return number of bytes written to @a buf | 347 | * @return number of bytes written to @a buf |
349 | */ | 348 | */ |
350 | static size_t | 349 | static size_t |
351 | do_report_collection_point (void *cls, size_t size, void *buf) | 350 | do_report_value (void *cls, size_t size, void *buf) |
352 | { | 351 | { |
353 | struct CadetChannelContext *cc = cls; | 352 | struct CadetChannelContext *cc = cls; |
354 | size_t written = 0; | 353 | size_t written = 0; |
@@ -386,8 +385,7 @@ do_report_collection_point (void *cls, size_t size, void *buf) | |||
386 | * @param tc unused | 385 | * @param tc unused |
387 | */ | 386 | */ |
388 | static void | 387 | static void |
389 | report_collection_point (void *cls, | 388 | report_value (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
390 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
391 | { | 389 | { |
392 | struct ValueReportingContext *vrc = cls; | 390 | struct ValueReportingContext *vrc = cls; |
393 | struct GNUNET_SENSOR_SensorInfo *sensor = vrc->sensor; | 391 | struct GNUNET_SENSOR_SensorInfo *sensor = vrc->sensor; |
@@ -396,14 +394,14 @@ report_collection_point (void *cls, | |||
396 | size_t msg_size; | 394 | size_t msg_size; |
397 | 395 | ||
398 | vrc->cp_task = GNUNET_SCHEDULER_NO_TASK; | 396 | vrc->cp_task = GNUNET_SCHEDULER_NO_TASK; |
399 | if (0 == vrc->last_value_size) /* Did not receive a sensor value yet */ | 397 | if (0 == vrc->last_value_size) /* Did not receive a sensor value yet */ |
400 | { | 398 | { |
401 | LOG (GNUNET_ERROR_TYPE_WARNING, | 399 | LOG (GNUNET_ERROR_TYPE_WARNING, |
402 | "Did not receive a value from `%s' to report yet.\n", | 400 | "Did not receive a value from `%s' to report yet.\n", |
403 | vrc->sensor->name); | 401 | vrc->sensor->name); |
404 | vrc->cp_task = | 402 | vrc->cp_task = |
405 | GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval, | 403 | GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval, |
406 | &report_collection_point, vrc); | 404 | &report_value, vrc); |
407 | return; | 405 | return; |
408 | } | 406 | } |
409 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 407 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -420,8 +418,7 @@ report_collection_point (void *cls, | |||
420 | vrc->cp_task = | 418 | vrc->cp_task = |
421 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 419 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
422 | (GNUNET_TIME_UNIT_SECONDS, | 420 | (GNUNET_TIME_UNIT_SECONDS, |
423 | COLLECTION_RETRY), | 421 | COLLECTION_RETRY), &report_value, vrc); |
424 | &report_collection_point, vrc); | ||
425 | return; | 422 | return; |
426 | } | 423 | } |
427 | msg_size = construct_reading_message (vrc, &msg); | 424 | msg_size = construct_reading_message (vrc, &msg); |
@@ -430,11 +427,11 @@ report_collection_point (void *cls, | |||
430 | cc->pending_msg_size = msg_size; | 427 | cc->pending_msg_size = msg_size; |
431 | cc->th = | 428 | cc->th = |
432 | GNUNET_CADET_notify_transmit_ready (cc->c, GNUNET_YES, | 429 | GNUNET_CADET_notify_transmit_ready (cc->c, GNUNET_YES, |
433 | sensor->value_reporting_interval, msg_size, | 430 | sensor->value_reporting_interval, |
434 | &do_report_collection_point, cc); | 431 | msg_size, &do_report_value, cc); |
435 | vrc->cp_task = | 432 | vrc->cp_task = |
436 | GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval, | 433 | GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval, |
437 | &report_collection_point, vrc); | 434 | &report_value, vrc); |
438 | } | 435 | } |
439 | 436 | ||
440 | 437 | ||
@@ -442,7 +439,7 @@ report_collection_point (void *cls, | |||
442 | * Sensor value watch callback | 439 | * Sensor value watch callback |
443 | */ | 440 | */ |
444 | static int | 441 | static int |
445 | sensor_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | 442 | value_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
446 | { | 443 | { |
447 | struct ValueReportingContext *vrc = cls; | 444 | struct ValueReportingContext *vrc = cls; |
448 | 445 | ||
@@ -466,6 +463,34 @@ sensor_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | |||
466 | 463 | ||
467 | 464 | ||
468 | /** | 465 | /** |
466 | * Function called whenever a channel is destroyed. Should clean up | ||
467 | * any associated state. | ||
468 | * | ||
469 | * It must NOT call #GNUNET_CADET_channel_destroy on the channel. | ||
470 | * | ||
471 | * @param cls closure (set from #GNUNET_CADET_connect) | ||
472 | * @param channel connection to the other end (henceforth invalid) | ||
473 | * @param channel_ctx place where local state associated | ||
474 | * with the channel is stored | ||
475 | */ | ||
476 | static void | ||
477 | cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel, | ||
478 | void *channel_ctx) | ||
479 | { | ||
480 | struct CadetChannelContext *cc = channel_ctx; | ||
481 | |||
482 | if (GNUNET_YES == cc->destroying) | ||
483 | return; | ||
484 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
485 | "Received a `channel destroyed' notification from CADET, " | ||
486 | "cleaning up.\n"); | ||
487 | GNUNET_CONTAINER_DLL_remove (cc_head, cc_tail, cc); | ||
488 | cc->c = NULL; | ||
489 | destroy_cadet_channel_context (cc); | ||
490 | } | ||
491 | |||
492 | |||
493 | /** | ||
469 | * Iterator for defined sensors | 494 | * Iterator for defined sensors |
470 | * Watches sensors for readings to report | 495 | * Watches sensors for readings to report |
471 | * | 496 | * |
@@ -481,76 +506,44 @@ init_sensor_reporting (void *cls, const struct GNUNET_HashCode *key, | |||
481 | struct GNUNET_SENSOR_SensorInfo *sensor = value; | 506 | struct GNUNET_SENSOR_SensorInfo *sensor = value; |
482 | struct ValueReportingContext *vrc; | 507 | struct ValueReportingContext *vrc; |
483 | 508 | ||
484 | if (NULL == sensor->collection_point || | 509 | if (NULL == sensor->collection_point || GNUNET_NO == sensor->report_values) |
485 | (GNUNET_NO == sensor->report_values && GNUNET_NO == sensor->report_anomalies)) | ||
486 | return GNUNET_YES; | 510 | return GNUNET_YES; |
511 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
512 | "Reporting sensor `%s' values to collection point `%s' every %s.\n", | ||
513 | sensor->name, GNUNET_i2s_full (sensor->collection_point), | ||
514 | GNUNET_STRINGS_relative_time_to_string (sensor->value_reporting_interval, | ||
515 | GNUNET_YES)); | ||
487 | vrc = GNUNET_new (struct ValueReportingContext); | 516 | vrc = GNUNET_new (struct ValueReportingContext); |
488 | vrc->sensor = sensor; | 517 | vrc->sensor = sensor; |
489 | vrc->last_value = NULL; | 518 | vrc->last_value = NULL; |
490 | vrc->last_value_size = 0; | 519 | vrc->last_value_size = 0; |
491 | vrc->wc = | 520 | vrc->wc = |
492 | GNUNET_PEERSTORE_watch (peerstore, "sensor", &mypeerid, sensor->name, | 521 | GNUNET_PEERSTORE_watch (peerstore, "sensor", &mypeerid, sensor->name, |
493 | &sensor_watch_cb, vrc); | 522 | &value_watch_cb, vrc); |
494 | if (NULL != sensor->collection_point) | 523 | vrc->cp_task = |
495 | { | 524 | GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval, |
496 | LOG (GNUNET_ERROR_TYPE_INFO, | 525 | &report_value, vrc); |
497 | "Will start reporting sensor `%s' values to " | ||
498 | "collection point `%s' every %s.\n", sensor->name, | ||
499 | GNUNET_i2s_full (sensor->collection_point), | ||
500 | GNUNET_STRINGS_relative_time_to_string (sensor->value_reporting_interval, | ||
501 | GNUNET_YES)); | ||
502 | vrc->cp_task = | ||
503 | GNUNET_SCHEDULER_add_delayed (sensor->value_reporting_interval, | ||
504 | &report_collection_point, vrc); | ||
505 | } | ||
506 | GNUNET_CONTAINER_DLL_insert (vrc_head, vrc_tail, vrc); | 526 | GNUNET_CONTAINER_DLL_insert (vrc_head, vrc_tail, vrc); |
507 | return GNUNET_YES; | 527 | return GNUNET_YES; |
508 | } | 528 | } |
509 | 529 | ||
510 | 530 | ||
511 | /** | 531 | /** |
512 | * Function called whenever a channel is destroyed. Should clean up | 532 | * Start the sensor value reporting module |
513 | * any associated state. | ||
514 | * | ||
515 | * It must NOT call #GNUNET_CADET_channel_destroy on the channel. | ||
516 | * | ||
517 | * @param cls closure (set from #GNUNET_CADET_connect) | ||
518 | * @param channel connection to the other end (henceforth invalid) | ||
519 | * @param channel_ctx place where local state associated | ||
520 | * with the channel is stored | ||
521 | */ | ||
522 | static void | ||
523 | cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel, | ||
524 | void *channel_ctx) | ||
525 | { | ||
526 | struct CadetChannelContext *cc = channel_ctx; | ||
527 | |||
528 | if (GNUNET_YES == cc->destroying) | ||
529 | return; | ||
530 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
531 | "Received a `channel destroyed' notification from CADET, " | ||
532 | "cleaning up.\n"); | ||
533 | GNUNET_CONTAINER_DLL_remove (cc_head, cc_tail, cc); | ||
534 | cc->c = NULL; | ||
535 | destroy_cadet_channel_context (cc); | ||
536 | } | ||
537 | |||
538 | /** | ||
539 | * Start the sensor reporting module | ||
540 | * | 533 | * |
541 | * @param c our service configuration | 534 | * @param c our service configuration |
542 | * @param sensors multihashmap of loaded sensors | 535 | * @param sensors multihashmap of loaded sensors |
543 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | 536 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise |
544 | */ | 537 | */ |
545 | int | 538 | int |
546 | SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c, | 539 | SENSOR_reporting_value_start (const struct GNUNET_CONFIGURATION_Handle *c, |
547 | struct GNUNET_CONTAINER_MultiHashMap *sensors) | 540 | struct GNUNET_CONTAINER_MultiHashMap *sensors) |
548 | { | 541 | { |
549 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 542 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { |
550 | {NULL, 0, 0} | 543 | {NULL, 0, 0} |
551 | }; | 544 | }; |
552 | 545 | ||
553 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor reporting module.\n"); | 546 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor value reporting module.\n"); |
554 | GNUNET_assert (NULL != sensors); | 547 | GNUNET_assert (NULL != sensors); |
555 | cfg = c; | 548 | cfg = c; |
556 | peerstore = GNUNET_PEERSTORE_connect (cfg); | 549 | peerstore = GNUNET_PEERSTORE_connect (cfg); |
@@ -558,7 +551,7 @@ SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
558 | { | 551 | { |
559 | LOG (GNUNET_ERROR_TYPE_ERROR, | 552 | LOG (GNUNET_ERROR_TYPE_ERROR, |
560 | _("Failed to connect to peerstore service.\n")); | 553 | _("Failed to connect to peerstore service.\n")); |
561 | SENSOR_reporting_stop (); | 554 | SENSOR_reporting_value_stop (); |
562 | return GNUNET_SYSERR; | 555 | return GNUNET_SYSERR; |
563 | } | 556 | } |
564 | cadet = | 557 | cadet = |
@@ -567,7 +560,7 @@ SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
567 | if (NULL == cadet) | 560 | if (NULL == cadet) |
568 | { | 561 | { |
569 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CADET service.\n")); | 562 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CADET service.\n")); |
570 | SENSOR_reporting_stop (); | 563 | SENSOR_reporting_value_stop (); |
571 | return GNUNET_SYSERR; | 564 | return GNUNET_SYSERR; |
572 | } | 565 | } |
573 | GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid); | 566 | GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid); |
@@ -575,4 +568,4 @@ SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
575 | return GNUNET_OK; | 568 | return GNUNET_OK; |
576 | } | 569 | } |
577 | 570 | ||
578 | /* end of gnunet-service-sensor-reporting.c */ | 571 | /* end of gnunet-service-sensor_reporting_value.c */ |
diff --git a/src/sensor/gnunet-service-sensor-update.c b/src/sensor/gnunet-service-sensor_update.c index 3d3eb335d..1d8b32832 100644 --- a/src/sensor/gnunet-service-sensor-update.c +++ b/src/sensor/gnunet-service-sensor_update.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file sensor/gnunet-service-sensor-update.c | 22 | * @file sensor/gnunet-service-sensor_update.c |
23 | * @brief sensor service update functionality | 23 | * @brief sensor service update functionality |
24 | * @author Omar Tarabai | 24 | * @author Omar Tarabai |
25 | */ | 25 | */ |
@@ -785,4 +785,4 @@ SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
785 | return GNUNET_OK; | 785 | return GNUNET_OK; |
786 | } | 786 | } |
787 | 787 | ||
788 | /* end of gnunet-service-sensor-update.c */ | 788 | /* end of gnunet-service-sensor_update.c */ |
diff --git a/src/sensor/sensor.h b/src/sensor/sensor.h index 0fdb5a6e2..45fe2edda 100644 --- a/src/sensor/sensor.h +++ b/src/sensor/sensor.h | |||
@@ -81,22 +81,41 @@ SENSOR_analysis_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
81 | 81 | ||
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Stop sensor reporting module | 84 | * Stop sensor value reporting module |
85 | */ | 85 | */ |
86 | void | 86 | void |
87 | SENSOR_reporting_stop (); | 87 | SENSOR_reporting_value_stop (); |
88 | 88 | ||
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Start the sensor reporting module | 91 | * Start the sensor value reporting module |
92 | * | 92 | * |
93 | * @param c our service configuration | 93 | * @param c our service configuration |
94 | * @param sensors multihashmap of loaded sensors | 94 | * @param sensors multihashmap of loaded sensors |
95 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | 95 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise |
96 | */ | 96 | */ |
97 | int | 97 | int |
98 | SENSOR_reporting_start (const struct GNUNET_CONFIGURATION_Handle *c, | 98 | SENSOR_reporting_value_start (const struct GNUNET_CONFIGURATION_Handle *c, |
99 | struct GNUNET_CONTAINER_MultiHashMap *sensors); | 99 | struct GNUNET_CONTAINER_MultiHashMap *sensors); |
100 | |||
101 | |||
102 | /** | ||
103 | * Stop sensor anomaly reporting module | ||
104 | */ | ||
105 | void | ||
106 | SENSOR_reporting_anomaly_stop (); | ||
107 | |||
108 | |||
109 | /** | ||
110 | * Start the sensor anomaly reporting module | ||
111 | * | ||
112 | * @param c our service configuration | ||
113 | * @param sensors multihashmap of loaded sensors | ||
114 | * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise | ||
115 | */ | ||
116 | int | ||
117 | SENSOR_reporting_anomaly_start (const struct GNUNET_CONFIGURATION_Handle *c, | ||
118 | struct GNUNET_CONTAINER_MultiHashMap *sensors); | ||
100 | 119 | ||
101 | 120 | ||
102 | /** | 121 | /** |