diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sensor/gnunet-sensor-profiler.c | 91 |
1 files changed, 88 insertions, 3 deletions
diff --git a/src/sensor/gnunet-sensor-profiler.c b/src/sensor/gnunet-sensor-profiler.c index 848fdf9c6..d236d1780 100644 --- a/src/sensor/gnunet-sensor-profiler.c +++ b/src/sensor/gnunet-sensor-profiler.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include "gnunet_testbed_service.h" | 38 | #include "gnunet_testbed_service.h" |
39 | #include "gnunet_peerstore_service.h" | 39 | #include "gnunet_peerstore_service.h" |
40 | #include "gnunet_sensor_service.h" | 40 | #include "gnunet_sensor_service.h" |
41 | #include "gnunet_sensor_util_lib.h" | ||
41 | 42 | ||
42 | /** | 43 | /** |
43 | * Information about a single peer | 44 | * Information about a single peer |
@@ -108,6 +109,26 @@ static struct GNUNET_TESTBED_Operation *peerstore_op; | |||
108 | */ | 109 | */ |
109 | static struct GNUNET_PEERSTORE_Handle *peerstore; | 110 | static struct GNUNET_PEERSTORE_Handle *peerstore; |
110 | 111 | ||
112 | /** | ||
113 | * Dashboard service on collection point started? | ||
114 | */ | ||
115 | static int dashboard_service_started = GNUNET_NO; | ||
116 | |||
117 | /** | ||
118 | * Number of peers started the sensor service successfully | ||
119 | */ | ||
120 | static int sensor_services_started = 0; | ||
121 | |||
122 | /** | ||
123 | * Array of sensor names to be used for watching peerstore records | ||
124 | */ | ||
125 | static char **sensor_names; | ||
126 | |||
127 | /** | ||
128 | * Size of 'sensor_names' array | ||
129 | */ | ||
130 | static unsigned int sensor_names_size = 0; | ||
131 | |||
111 | 132 | ||
112 | /** | 133 | /** |
113 | * Copy directory recursively | 134 | * Copy directory recursively |
@@ -126,7 +147,15 @@ copy_dir (const char *src, const char *dst); | |||
126 | static void | 147 | static void |
127 | do_shutdown () // TODO: schedule timeout shutdown | 148 | do_shutdown () // TODO: schedule timeout shutdown |
128 | { | 149 | { |
150 | int i; | ||
151 | |||
129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n"); | 152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n"); |
153 | if (NULL != sensor_names) | ||
154 | { | ||
155 | for (i = 0; i < sensor_names_size; i++) | ||
156 | GNUNET_free (sensor_names[i]); | ||
157 | GNUNET_array_grow (sensor_names, sensor_names_size, 0); | ||
158 | } | ||
130 | if (NULL != peerstore_op) | 159 | if (NULL != peerstore_op) |
131 | { | 160 | { |
132 | GNUNET_TESTBED_operation_done (peerstore_op); | 161 | GNUNET_TESTBED_operation_done (peerstore_op); |
@@ -209,6 +238,7 @@ sensor_dir_scanner (void *cls, const char *filename) | |||
209 | const char *file_basename; | 238 | const char *file_basename; |
210 | char *dst_path; | 239 | char *dst_path; |
211 | struct GNUNET_CONFIGURATION_Handle *sensor_cfg; | 240 | struct GNUNET_CONFIGURATION_Handle *sensor_cfg; |
241 | char *sensor_name; | ||
212 | 242 | ||
213 | file_basename = GNUNET_STRINGS_get_short_name (filename); | 243 | file_basename = GNUNET_STRINGS_get_short_name (filename); |
214 | GNUNET_asprintf (&dst_path, "%s%s%s", sensor_dst_dir, DIR_SEPARATOR_STR, | 244 | GNUNET_asprintf (&dst_path, "%s%s%s", sensor_dst_dir, DIR_SEPARATOR_STR, |
@@ -219,6 +249,9 @@ sensor_dir_scanner (void *cls, const char *filename) | |||
219 | } | 249 | } |
220 | else | 250 | else |
221 | { | 251 | { |
252 | sensor_name = GNUNET_strdup(file_basename); | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Saving sensor name `%s'.\n", sensor_name); | ||
254 | GNUNET_array_append(sensor_names, sensor_names_size, sensor_name); | ||
222 | sensor_cfg = GNUNET_CONFIGURATION_create (); | 255 | sensor_cfg = GNUNET_CONFIGURATION_create (); |
223 | GNUNET_assert (GNUNET_OK == | 256 | GNUNET_assert (GNUNET_OK == |
224 | GNUNET_CONFIGURATION_parse (sensor_cfg, filename)); | 257 | GNUNET_CONFIGURATION_parse (sensor_cfg, filename)); |
@@ -273,8 +306,46 @@ dashboard_started (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
273 | GNUNET_assert (0); | 306 | GNUNET_assert (0); |
274 | } | 307 | } |
275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dashboard service started.\n"); | 308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dashboard service started.\n"); |
276 | //TODO: | ||
277 | GNUNET_TESTBED_operation_done (op); | 309 | GNUNET_TESTBED_operation_done (op); |
310 | dashboard_service_started = GNUNET_YES; | ||
311 | //TODO: | ||
312 | } | ||
313 | |||
314 | |||
315 | /** | ||
316 | * Function called by PEERSTORE for each matching record. | ||
317 | * | ||
318 | * @param cls closure | ||
319 | * @param record peerstore record information | ||
320 | * @param emsg error message, or NULL if no errors | ||
321 | * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop | ||
322 | */ | ||
323 | static int | ||
324 | peerstore_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, | ||
325 | char *emsg) | ||
326 | { | ||
327 | struct PeerInfo *peer = cls; | ||
328 | struct GNUNET_SENSOR_DashboardAnomalyEntry *anomaly; | ||
329 | |||
330 | if (NULL != emsg) | ||
331 | { | ||
332 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | ||
333 | GNUNET_assert (0); | ||
334 | } | ||
335 | GNUNET_assert (record->value_size == | ||
336 | sizeof (struct GNUNET_SENSOR_DashboardAnomalyEntry)); | ||
337 | anomaly = record->value; | ||
338 | GNUNET_assert (0 == | ||
339 | GNUNET_CRYPTO_cmp_peer_identity (&peer->peer_id, | ||
340 | record->peer)); | ||
341 | printf ("Anomaly report:\n" | ||
342 | " Peer: `%s'\n" | ||
343 | " Sensor: `%s'\n" | ||
344 | " Anomalous: `%d'\n" | ||
345 | " Anomalous neighbors: %f.\n\n", | ||
346 | GNUNET_i2s (&peer->peer_id), | ||
347 | record->key, anomaly->anomalous, anomaly->anomalous_neighbors); | ||
348 | return GNUNET_YES; | ||
278 | } | 349 | } |
279 | 350 | ||
280 | 351 | ||
@@ -291,13 +362,26 @@ static void | |||
291 | peerstore_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 362 | peerstore_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, |
292 | void *ca_result, const char *emsg) | 363 | void *ca_result, const char *emsg) |
293 | { | 364 | { |
365 | int i; | ||
366 | int j; | ||
367 | struct PeerInfo *peer; | ||
368 | |||
294 | if (NULL != emsg) | 369 | if (NULL != emsg) |
295 | { | 370 | { |
296 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | 371 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); |
297 | GNUNET_assert (0); | 372 | GNUNET_assert (0); |
298 | } | 373 | } |
299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peerstore service.\n"); | 374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peerstore service.\n"); |
300 | //TODO | 375 | /* Watch for anomaly reports from other peers */ |
376 | for (i = 0; i < num_peers; i++) | ||
377 | { | ||
378 | peer = &all_peers_info[i]; | ||
379 | for (j = 0; j < sensor_names_size; j++) | ||
380 | { | ||
381 | GNUNET_PEERSTORE_watch (peerstore, "sensordashboard-anomalies", &peer->peer_id, | ||
382 | sensor_names[j], &peerstore_watch_cb, peer); | ||
383 | } | ||
384 | } | ||
301 | } | 385 | } |
302 | 386 | ||
303 | 387 | ||
@@ -356,8 +440,9 @@ sensor_service_started (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
356 | } | 440 | } |
357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sensor service started on peer `%s'.\n", | 441 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sensor service started on peer `%s'.\n", |
358 | GNUNET_i2s (&peer->peer_id)); | 442 | GNUNET_i2s (&peer->peer_id)); |
359 | //TODO: | ||
360 | GNUNET_TESTBED_operation_done (op); | 443 | GNUNET_TESTBED_operation_done (op); |
444 | sensor_services_started ++; | ||
445 | //TODO | ||
361 | } | 446 | } |
362 | 447 | ||
363 | 448 | ||