aboutsummaryrefslogtreecommitdiff
path: root/src/sensor
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-08-05 16:27:13 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-08-05 16:27:13 +0000
commitd5d82faf0c8ef87b9bd4171f3e880ff006ec693c (patch)
treed55cdf69e6e3e33f9709db2f120ae36f529305d9 /src/sensor
parent8a9baa7ae446c2eacb18a5290c98ae59bc2ad857 (diff)
downloadgnunet-d5d82faf0c8ef87b9bd4171f3e880ff006ec693c.tar.gz
gnunet-d5d82faf0c8ef87b9bd4171f3e880ff006ec693c.zip
sensor: towards anomaly reporting
Diffstat (limited to 'src/sensor')
-rw-r--r--src/sensor/gnunet-service-sensor_analysis.c12
-rw-r--r--src/sensor/gnunet-service-sensor_reporting_anomaly.c426
-rw-r--r--src/sensor/sensor.h15
3 files changed, 340 insertions, 113 deletions
diff --git a/src/sensor/gnunet-service-sensor_analysis.c b/src/sensor/gnunet-service-sensor_analysis.c
index 46422d039..63249a4e2 100644
--- a/src/sensor/gnunet-service-sensor_analysis.c
+++ b/src/sensor/gnunet-service-sensor_analysis.c
@@ -209,11 +209,7 @@ sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg)
209 model->anomalous = GNUNET_YES; 209 model->anomalous = GNUNET_YES;
210 LOG (GNUNET_ERROR_TYPE_WARNING, 210 LOG (GNUNET_ERROR_TYPE_WARNING,
211 "Anomaly state started for sensor `%s'.\n", model->sensor->name); 211 "Anomaly state started for sensor `%s'.\n", model->sensor->name);
212 GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid, 212 SENSOR_reporting_anomaly_update (model->sensor, model->anomalous);
213 model->sensor->name, &model->anomalous,
214 sizeof (model->anomalous),
215 GNUNET_TIME_absolute_get (),
216 GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL);
217 } 213 }
218 } 214 }
219 else 215 else
@@ -226,11 +222,7 @@ sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg)
226 model->anomalous = GNUNET_NO; 222 model->anomalous = GNUNET_NO;
227 LOG (GNUNET_ERROR_TYPE_INFO, "Anomaly state stopped for sensor `%s'.\n", 223 LOG (GNUNET_ERROR_TYPE_INFO, "Anomaly state stopped for sensor `%s'.\n",
228 model->sensor->name); 224 model->sensor->name);
229 GNUNET_PEERSTORE_store (peerstore, "senosr-analysis", &peerid, 225 SENSOR_reporting_anomaly_update (model->sensor, model->anomalous);
230 model->sensor->name, &model->anomalous,
231 sizeof (model->anomalous),
232 GNUNET_TIME_absolute_get (),
233 GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL);
234 } 226 }
235 } 227 }
236 return GNUNET_YES; 228 return GNUNET_YES;
diff --git a/src/sensor/gnunet-service-sensor_reporting_anomaly.c b/src/sensor/gnunet-service-sensor_reporting_anomaly.c
index 9a7a4eeb0..ff07c2e52 100644
--- a/src/sensor/gnunet-service-sensor_reporting_anomaly.c
+++ b/src/sensor/gnunet-service-sensor_reporting_anomaly.c
@@ -31,47 +31,64 @@
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting-anomaly",__VA_ARGS__) 32#define LOG(kind,...) GNUNET_log_from (kind, "sensor-reporting-anomaly",__VA_ARGS__)
33 33
34struct AnomalyReportingContext 34struct AnomalyInfo
35{ 35{
36 36
37 /** 37 /**
38 * DLL 38 * DLL
39 */ 39 */
40 struct AnomalyReportingContext *prev; 40 struct AnomalyInfo *prev;
41 41
42 /** 42 /**
43 * DLL 43 * DLL
44 */ 44 */
45 struct AnomalyReportingContext *next; 45 struct AnomalyInfo *next;
46 46
47 /** 47 /**
48 * Sensor information 48 * Sensor information
49 */ 49 */
50 struct GNUNET_SENSOR_SensorInfo *sensor; 50 struct GNUNET_SENSOR_SensorInfo *sensor;
51 51
52 /**
53 * Current anomalous status of sensor
54 */
55 int anomalous;
56
57 /**
58 * List of peers that reported an anomaly for this sensor
59 */
60 struct GNUNET_CONTAINER_MultiPeerMap *anomalous_neighbors;
61
52}; 62};
53 63
54/** 64/**
55 * Context of a connection to a peer through CORE 65 * Information about a connected CORE peer.
66 * Note that we only know about a connected peer if it is running the same
67 * application (sensor anomaly reporting) as us.
56 */ 68 */
57struct CorePeerContext 69struct CorePeer
58{ 70{
59 71
60 /** 72 /**
61 * DLL 73 * DLL
62 */ 74 */
63 struct CorePeerContext *prev; 75 struct CorePeer *prev;
64 76
65 /** 77 /**
66 * DLL 78 * DLL
67 */ 79 */
68 struct CorePeerContext *next; 80 struct CorePeer *next;
69 81
70 /** 82 /**
71 * Peer identity of connected peer 83 * Peer identity of connected peer
72 */ 84 */
73 struct GNUNET_PeerIdentity *peerid; 85 struct GNUNET_PeerIdentity *peerid;
74 86
87 /**
88 * Message queue for messages to be sent to this peer
89 */
90 struct GNUNET_MQ_Handle *mq;
91
75}; 92};
76 93
77 94
@@ -81,6 +98,11 @@ struct CorePeerContext
81static const struct GNUNET_CONFIGURATION_Handle *cfg; 98static const struct GNUNET_CONFIGURATION_Handle *cfg;
82 99
83/** 100/**
101 * Multihashmap of loaded sensors
102 */
103static struct GNUNET_CONTAINER_MultiHashMap *sensors;
104
105/**
84 * Handle to core service 106 * Handle to core service
85 */ 107 */
86static struct GNUNET_CORE_Handle *core; 108static struct GNUNET_CORE_Handle *core;
@@ -91,35 +113,74 @@ static struct GNUNET_CORE_Handle *core;
91static struct GNUNET_PeerIdentity mypeerid; 113static struct GNUNET_PeerIdentity mypeerid;
92 114
93/** 115/**
94 * Head of DLL of anomaly reporting contexts 116 * Head of DLL of anomaly info structs
95 */ 117 */
96static struct AnomalyReportingContext *arc_head; 118static struct AnomalyInfo *ai_head;
97 119
98/** 120/**
99 * Tail of DLL of anomaly reporting contexts 121 * Tail of DLL of anomaly info structs
100 */ 122 */
101static struct AnomalyReportingContext *arc_tail; 123static struct AnomalyInfo *ai_tail;
102 124
103/** 125/**
104 * Head of DLL of CORE peer contexts 126 * Head of DLL of CORE peers
105 */ 127 */
106static struct CorePeerContext *cp_head; 128static struct CorePeer *cp_head;
107 129
108/** 130/**
109 * Tail of DLL of CORE peer contexts 131 * Tail of DLL of CORE peers
132 */
133static struct CorePeer *cp_tail;
134
135/**
136 * Is the module started?
137 */
138static int module_running = GNUNET_NO;
139
140/**
141 * Number of known neighborhood peers
142 */
143static int neighborhood;
144
145
146/**
147 * Destroy anomaly info struct
148 *
149 * @param ai struct to destroy
110 */ 150 */
111static struct CorePeerContext *cp_tail; 151static void
152destroy_anomaly_info (struct AnomalyInfo *ai)
153{
154 if (NULL != ai->anomalous_neighbors)
155 GNUNET_CONTAINER_multipeermap_destroy (ai->anomalous_neighbors);
156 GNUNET_free (ai);
157}
112 158
113 159
114/** 160/**
115 * Destroy anomaly reporting context struct 161 * Destroy core peer struct
116 * 162 *
117 * @param arc struct to destroy 163 * @param cp struct to destroy
118 */ 164 */
119static void 165static void
120destroy_anomaly_reporting_context (struct AnomalyReportingContext *arc) 166destroy_core_peer (struct CorePeer *cp)
121{ 167{
122 GNUNET_free (arc); 168 struct AnomalyInfo *ai;
169
170 if (NULL != cp->mq)
171 {
172 GNUNET_MQ_destroy (cp->mq);
173 cp->mq = NULL;
174 }
175 ai = ai_head;
176 while (NULL != ai)
177 {
178 GNUNET_assert (NULL != ai->anomalous_neighbors);
179 GNUNET_CONTAINER_multipeermap_remove_all (ai->anomalous_neighbors,
180 cp->peerid);
181 ai = ai->next;
182 }
183 GNUNET_free (cp);
123} 184}
124 185
125 186
@@ -129,98 +190,150 @@ destroy_anomaly_reporting_context (struct AnomalyReportingContext *arc)
129void 190void
130SENSOR_reporting_anomaly_stop () 191SENSOR_reporting_anomaly_stop ()
131{ 192{
132 struct AnomalyReportingContext *arc; 193 struct AnomalyInfo *ai;
194 struct CorePeer *cp;
133 195
134 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor anomaly reporting module.\n"); 196 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping sensor anomaly reporting module.\n");
135 //TODO: destroy core peer contexts 197 module_running = GNUNET_NO;
136 //TODO: destroy core connection 198 ai = ai_head;
137 arc = arc_head; 199 while (NULL != ai)
138 while (NULL != arc) 200 {
201 GNUNET_CONTAINER_DLL_remove (ai_head, ai_tail, ai);
202 destroy_anomaly_info (ai);
203 ai = ai_head;
204 }
205 cp = cp_head;
206 while (NULL != cp)
139 { 207 {
140 GNUNET_CONTAINER_DLL_remove (arc_head, arc_tail, arc); 208 GNUNET_CONTAINER_DLL_remove (cp_head, cp_tail, cp);
141 destroy_anomaly_reporting_context (arc); 209 destroy_core_peer (cp);
142 arc = arc_head; 210 cp = cp_head;
211 }
212 neighborhood = 0;
213 if (NULL != core)
214 {
215 GNUNET_CORE_disconnect (core);
216 core = NULL;
143 } 217 }
144} 218}
145 219
146 220
147/** 221/**
148 * Iterator for defined sensors 222 * Gets the anomaly info struct related to the given sensor
149 * Watches sensors for anomaly status change to report
150 * 223 *
151 * @param cls unused 224 * @param sensor Sensor to search by
152 * @param key unused
153 * @param value a `struct GNUNET_SENSOR_SensorInfo *` with sensor information
154 * @return #GNUNET_YES to continue iterations
155 */ 225 */
156static int 226static struct AnomalyInfo *
157init_sensor_reporting (void *cls, const struct GNUNET_HashCode *key, 227get_anomaly_info_by_sensor (struct GNUNET_SENSOR_SensorInfo *sensor)
158 void *value)
159{ 228{
160 struct GNUNET_SENSOR_SensorInfo *sensor = value; 229 struct AnomalyInfo *ai;
161 struct AnomalyReportingContext *arc; 230
162 231 ai = ai_head;
163 if (NULL == sensor->collection_point) 232 while (NULL != ai)
164 return GNUNET_YES; 233 {
165 LOG (GNUNET_ERROR_TYPE_INFO, 234 if (ai->sensor == sensor)
166 "Reporting sensor `%s' anomalies to collection point `%s'.\n", 235 {
167 sensor->name, GNUNET_i2s_full (sensor->collection_point)); 236 return ai;
168 arc = GNUNET_new (struct AnomalyReportingContext); 237 }
169 arc->sensor = sensor; 238 ai = ai->next;
170 GNUNET_CONTAINER_DLL_insert (arc_head, arc_tail, arc); 239 }
171 //TODO 240 return NULL;
172 return GNUNET_YES;
173} 241}
174 242
175 243
176/** 244/**
177 * Function called after #GNUNET_CORE_connect has succeeded (or failed 245 * Create an anomaly report message from a given anomaly info structb inside an
178 * for good). Note that the private key of the peer is intentionally 246 * MQ envelope.
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 * 247 *
185 * @param cls closure (unused) 248 * @param ai Anomaly info struct to use
186 * @param my_identity ID of this peer, NULL if we failed 249 * @return
250 */
251static struct GNUNET_MQ_Envelope *
252create_anomaly_report_message (struct AnomalyInfo *ai)
253{
254 struct AnomalyReportMessage *arm;
255 struct GNUNET_MQ_Envelope *ev;
256
257 ev = GNUNET_MQ_msg (arm, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT);
258 GNUNET_CRYPTO_hash (ai->sensor->name, strlen (ai->sensor->name) + 1,
259 &arm->sensorname_hash);
260 arm->sensorversion_major = ai->sensor->version_major;
261 arm->sensorversion_minor = ai->sensor->version_minor;
262 arm->anomalous = ai->anomalous;
263 arm->anomalous_neighbors =
264 ((float) GNUNET_CONTAINER_multipeermap_size (ai->anomalous_neighbors)) /
265 neighborhood;
266 return ev;
267}
268
269
270/**
271 * Send given anomaly info report to given core peer.
272 *
273 * @param cp Core peer to send the report to
274 * @param ai Anomaly info to report
187 */ 275 */
188static void 276static void
189core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) 277send_anomaly_report (struct CorePeer *cp, struct AnomalyInfo *ai)
190{ 278{
191 if (NULL == my_identity) 279 struct GNUNET_MQ_Envelope *ev;
192 { 280
193 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CORE service.\n")); 281 GNUNET_assert (NULL != cp->mq);
194 SENSOR_reporting_anomaly_stop (); 282 ev = create_anomaly_report_message (ai);
195 return; 283 GNUNET_MQ_send (cp->mq, ev);
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} 284}
205 285
206 286
207/** 287/**
208 * Method called whenever a given peer connects through CORE. 288 * An inbound anomaly report is received from a peer through CORE.
209 * 289 *
210 * @param cls closure (unused) 290 * @param cls closure (unused)
211 * @param peer peer identity this notification is about 291 * @param peer the other peer involved
292 * @param message the actual message
293 * @return #GNUNET_OK to keep the connection open,
294 * #GNUNET_SYSERR to close connection to the peer (signal serious error)
212 */ 295 */
213static void 296static int
214core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) 297handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
298 const struct GNUNET_MessageHeader *message)
215{ 299{
216 struct CorePeerContext *cp; 300 struct AnomalyReportMessage *arm;
301 struct GNUNET_SENSOR_SensorInfo *sensor;
302 struct AnomalyInfo *ai;
303 int peer_in_list;
217 304
218 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) 305 arm = (struct AnomalyReportMessage *) message;
219 return; 306 sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash);
220 cp = GNUNET_new (struct CorePeerContext); 307 if (NULL == sensor || sensor->version_major != arm->sensorversion_major ||
221 cp->peerid = (struct GNUNET_PeerIdentity *)peer; 308 sensor->version_minor != arm->sensorversion_minor)
222 GNUNET_CONTAINER_DLL_insert (cp_head, cp_tail, cp); 309 {
223 //TODO: report to peer your anomaly status 310 LOG (GNUNET_ERROR_TYPE_WARNING,
311 "I don't have the sensor reported by the peer `%s'.\n",
312 GNUNET_i2s (other));
313 return GNUNET_OK;
314 }
315 ai = get_anomaly_info_by_sensor (sensor);
316 GNUNET_assert (NULL != ai);
317 peer_in_list =
318 GNUNET_CONTAINER_multipeermap_contains (ai->anomalous_neighbors, other);
319 if (GNUNET_YES == ai->anomalous)
320 {
321 if (GNUNET_YES == peer_in_list)
322 GNUNET_break_op (0);
323 else
324 GNUNET_CONTAINER_multipeermap_put (ai->anomalous_neighbors, other, NULL,
325 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
326 }
327 else
328 {
329 if (GNUNET_NO == peer_in_list)
330 GNUNET_break_op (0);
331 else
332 GNUNET_CONTAINER_multipeermap_remove_all (ai->anomalous_neighbors, other);
333 }
334 //TODO: report to collection point if anomalous neigbors jump up or down
335 // by a configurable percentage or is now 0% or 100%
336 return GNUNET_OK;
224} 337}
225 338
226 339
@@ -233,19 +346,21 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
233static void 346static void
234core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) 347core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
235{ 348{
236 struct CorePeerContext *cp; 349 struct CorePeer *cp;
237 350
238 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) 351 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer))
239 return; 352 return;
353 neighborhood--;
240 cp = cp_head; 354 cp = cp_head;
241 while (NULL != cp) 355 while (NULL != cp)
242 { 356 {
243 if (peer == cp->peerid) 357 if (peer == cp->peerid)
244 { 358 {
245 GNUNET_CONTAINER_DLL_remove (cp_head, cp_tail, cp); 359 GNUNET_CONTAINER_DLL_remove (cp_head, cp_tail, cp);
246 //TODO: call peer context destroy function 360 destroy_core_peer (cp);
247 return; 361 return;
248 } 362 }
363 cp = cp->next;
249 } 364 }
250 LOG (GNUNET_ERROR_TYPE_ERROR, 365 LOG (GNUNET_ERROR_TYPE_ERROR,
251 _("Received disconnect notification from CORE" 366 _("Received disconnect notification from CORE"
@@ -254,21 +369,119 @@ core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
254 369
255 370
256/** 371/**
257 * An inbound message is received from a peer through CORE. 372 * Method called whenever a given peer connects through CORE.
258 * 373 *
259 * @param cls closure (unused) 374 * @param cls closure (unused)
260 * @param peer the other peer involved 375 * @param peer peer identity this notification is about
261 * @param message the actual message 376 */
262 * @return #GNUNET_OK to keep the connection open, 377static void
263 * #GNUNET_SYSERR to close connection to the peer (signal serious error) 378core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
379{
380 struct CorePeer *cp;
381 struct AnomalyInfo *ai;
382
383 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer))
384 return;
385 neighborhood++;
386 cp = GNUNET_new (struct CorePeer);
387 cp->peerid = (struct GNUNET_PeerIdentity *) peer;
388 cp->mq = GNUNET_CORE_mq_create (core, peer);
389 GNUNET_CONTAINER_DLL_insert (cp_head, cp_tail, cp);
390 /* Send any locally anomalous sensors to the new peer */
391 ai = ai_head;
392 while (NULL != ai)
393 {
394 if (GNUNET_YES == ai->anomalous)
395 send_anomaly_report (cp, ai);
396 ai = ai->next;
397 }
398}
399
400
401/**
402 * Function called after #GNUNET_CORE_connect has succeeded (or failed
403 * for good). Note that the private key of the peer is intentionally
404 * not exposed here; if you need it, your process should try to read
405 * the private key file directly (which should work if you are
406 * authorized...). Implementations of this function must not call
407 * #GNUNET_CORE_disconnect (other than by scheduling a new task to
408 * do this later).
409 *
410 * @param cls closure (unused)
411 * @param my_identity ID of this peer, NULL if we failed
412 */
413static void
414core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
415{
416 if (NULL == my_identity)
417 {
418 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CORE service.\n"));
419 SENSOR_reporting_anomaly_stop ();
420 return;
421 }
422 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, my_identity))
423 {
424 LOG (GNUNET_ERROR_TYPE_ERROR,
425 _("Peer identity received from CORE init doesn't match ours.\n"));
426 SENSOR_reporting_anomaly_stop ();
427 return;
428 }
429}
430
431
432/**
433 * Used by the analysis module to tell the reporting module about a change in
434 * the anomaly status of a sensor.
435 *
436 * @param sensor Related sensor
437 * @param anomalous The new sensor anomalous status
438 */
439void
440SENSOR_reporting_anomaly_update (struct GNUNET_SENSOR_SensorInfo *sensor,
441 int anomalous)
442{
443 struct AnomalyInfo *ai;
444 struct CorePeer *cp;
445
446 if (GNUNET_NO == module_running)
447 return;
448 ai = get_anomaly_info_by_sensor (sensor);
449 GNUNET_assert (NULL != ai);
450 ai->anomalous = anomalous;
451 /* Report change to all neighbors */
452 cp = cp_head;
453 while (NULL != cp)
454 {
455 send_anomaly_report (cp, ai);
456 cp = cp->next;
457 }
458 //TODO: report change to collection point if report_anomalies
459}
460
461
462/**
463 * Iterator for defined sensors and creates anomaly info context
464 *
465 * @param cls unused
466 * @param key unused
467 * @param value a `struct GNUNET_SENSOR_SensorInfo *` with sensor information
468 * @return #GNUNET_YES to continue iterations
264 */ 469 */
265static int 470static int
266core_inbound_cb (void *cls, 471init_sensor_reporting (void *cls, const struct GNUNET_HashCode *key,
267 const struct GNUNET_PeerIdentity *other, 472 void *value)
268 const struct GNUNET_MessageHeader *message)
269{ 473{
270 //TODO 474 struct GNUNET_SENSOR_SensorInfo *sensor = value;
271 return GNUNET_OK; 475 struct AnomalyInfo *ai;
476
477 ai = GNUNET_new (struct AnomalyInfo);
478
479 ai->sensor = sensor;
480 ai->anomalous = GNUNET_NO;
481 ai->anomalous_neighbors =
482 GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
483 GNUNET_CONTAINER_DLL_insert (ai_head, ai_tail, ai);
484 return GNUNET_YES;
272} 485}
273 486
274 487
@@ -276,26 +489,37 @@ core_inbound_cb (void *cls,
276 * Start the sensor anomaly reporting module 489 * Start the sensor anomaly reporting module
277 * 490 *
278 * @param c our service configuration 491 * @param c our service configuration
279 * @param sensors multihashmap of loaded sensors 492 * @param s multihashmap of loaded sensors
280 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise 493 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
281 */ 494 */
282int 495int
283SENSOR_reporting_anomaly_start (const struct GNUNET_CONFIGURATION_Handle *c, 496SENSOR_reporting_anomaly_start (const struct GNUNET_CONFIGURATION_Handle *c,
284 struct GNUNET_CONTAINER_MultiHashMap *sensors) 497 struct GNUNET_CONTAINER_MultiHashMap *s)
285{ 498{
286 static struct GNUNET_CORE_MessageHandler core_handlers[] = { 499 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
287 {NULL, 0, 0} //TODO 500 {&handle_anomaly_report, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT,
501 sizeof (struct AnomalyReportMessage)},
502 {NULL, 0, 0}
288 }; 503 };
289 504
290 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor anomaly reporting module.\n"); 505 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting sensor anomaly reporting module.\n");
291 GNUNET_assert (NULL != sensors); 506 GNUNET_assert (NULL != s);
507 sensors = s;
292 cfg = c; 508 cfg = c;
293 core = 509 core =
294 GNUNET_CORE_connect (cfg, NULL, &core_startup_cb, core_connect_cb, 510 GNUNET_CORE_connect (cfg, NULL, &core_startup_cb, core_connect_cb,
295 &core_disconnect_cb, core_inbound_cb, GNUNET_NO, 511 &core_disconnect_cb, NULL, GNUNET_YES, NULL,
296 NULL, GNUNET_YES, core_handlers); 512 GNUNET_YES, core_handlers);
513 if (NULL == core)
514 {
515 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to CORE service.\n"));
516 SENSOR_reporting_anomaly_stop ();
517 return GNUNET_SYSERR;
518 }
297 GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid); 519 GNUNET_CRYPTO_get_peer_identity (cfg, &mypeerid);
298 GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, NULL); 520 GNUNET_CONTAINER_multihashmap_iterate (sensors, &init_sensor_reporting, NULL);
521 neighborhood = 0;
522 module_running = GNUNET_YES;
299 return GNUNET_OK; 523 return GNUNET_OK;
300} 524}
301 525
diff --git a/src/sensor/sensor.h b/src/sensor/sensor.h
index 45fe2edda..3cca3b0c0 100644
--- a/src/sensor/sensor.h
+++ b/src/sensor/sensor.h
@@ -105,17 +105,28 @@ SENSOR_reporting_value_start (const struct GNUNET_CONFIGURATION_Handle *c,
105void 105void
106SENSOR_reporting_anomaly_stop (); 106SENSOR_reporting_anomaly_stop ();
107 107
108/**
109 * Used by the analysis module to tell the reporting module about a change in
110 * the anomaly status of a sensor.
111 *
112 * @param sensor Related sensor
113 * @param anomalous The new sensor anomalous status
114 */
115void
116SENSOR_reporting_anomaly_update (struct GNUNET_SENSOR_SensorInfo *sensor,
117 int anomalous);
118
108 119
109/** 120/**
110 * Start the sensor anomaly reporting module 121 * Start the sensor anomaly reporting module
111 * 122 *
112 * @param c our service configuration 123 * @param c our service configuration
113 * @param sensors multihashmap of loaded sensors 124 * @param s multihashmap of loaded sensors
114 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise 125 * @return #GNUNET_OK if started successfully, #GNUNET_SYSERR otherwise
115 */ 126 */
116int 127int
117SENSOR_reporting_anomaly_start (const struct GNUNET_CONFIGURATION_Handle *c, 128SENSOR_reporting_anomaly_start (const struct GNUNET_CONFIGURATION_Handle *c,
118 struct GNUNET_CONTAINER_MultiHashMap *sensors); 129 struct GNUNET_CONTAINER_MultiHashMap *s);
119 130
120 131
121/** 132/**