diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-09-18 17:10:50 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-09-18 17:10:50 +0000 |
commit | 0c50476ae0a91d23c71ab8f3dddd7feb9ccc2397 (patch) | |
tree | c3376ba86a9fd7deda45664d58694dbdd7b03783 /src/sensor | |
parent | e2ff8e18f5ea9e6be03f13c4482dedb6647d5e2c (diff) | |
download | gnunet-0c50476ae0a91d23c71ab8f3dddd7feb9ccc2397.tar.gz gnunet-0c50476ae0a91d23c71ab8f3dddd7feb9ccc2397.zip |
sensor: profiler prompts for peer reconnection
Diffstat (limited to 'src/sensor')
-rw-r--r-- | src/sensor/gnunet-sensor-profiler.c | 137 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_analysis.c | 8 |
2 files changed, 130 insertions, 15 deletions
diff --git a/src/sensor/gnunet-sensor-profiler.c b/src/sensor/gnunet-sensor-profiler.c index 783c6fd1e..4cd6b808d 100644 --- a/src/sensor/gnunet-sensor-profiler.c +++ b/src/sensor/gnunet-sensor-profiler.c | |||
@@ -76,6 +76,15 @@ struct DisconnectionContext | |||
76 | 76 | ||
77 | }; | 77 | }; |
78 | 78 | ||
79 | struct ConnectionContext | ||
80 | { | ||
81 | |||
82 | struct PeerInfo *p1; | ||
83 | |||
84 | struct PeerInfo *p2; | ||
85 | |||
86 | }; | ||
87 | |||
79 | 88 | ||
80 | /** | 89 | /** |
81 | * Name of the configuration file used | 90 | * Name of the configuration file used |
@@ -192,6 +201,26 @@ prompt_peer_disconnection (); | |||
192 | 201 | ||
193 | 202 | ||
194 | /** | 203 | /** |
204 | * Destroy a DisconnectionContext struct | ||
205 | */ | ||
206 | static void | ||
207 | destroy_dc (struct DisconnectionContext *dc) | ||
208 | { | ||
209 | if (NULL != dc->blacklist) | ||
210 | { | ||
211 | GNUNET_TRANSPORT_blacklist_cancel (dc->blacklist); | ||
212 | dc->blacklist = NULL; | ||
213 | } | ||
214 | if (NULL != dc->p1_transport_op) | ||
215 | { | ||
216 | GNUNET_TESTBED_operation_done (dc->p1_transport_op); | ||
217 | dc->p1_transport_op = NULL; | ||
218 | } | ||
219 | GNUNET_free (dc); | ||
220 | } | ||
221 | |||
222 | |||
223 | /** | ||
195 | * Do clean up and shutdown scheduler | 224 | * Do clean up and shutdown scheduler |
196 | */ | 225 | */ |
197 | static void | 226 | static void |
@@ -210,17 +239,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
210 | while (NULL != dc) | 239 | while (NULL != dc) |
211 | { | 240 | { |
212 | GNUNET_CONTAINER_DLL_remove (dc_head, dc_tail, dc); | 241 | GNUNET_CONTAINER_DLL_remove (dc_head, dc_tail, dc); |
213 | if (NULL != dc->blacklist) | 242 | destroy_dc (dc); |
214 | { | ||
215 | GNUNET_TRANSPORT_blacklist_cancel (dc->blacklist); | ||
216 | dc->blacklist = NULL; | ||
217 | } | ||
218 | if (NULL != dc->p1_transport_op) | ||
219 | { | ||
220 | GNUNET_TESTBED_operation_done (dc->p1_transport_op); | ||
221 | dc->p1_transport_op = NULL; | ||
222 | } | ||
223 | GNUNET_free (dc); | ||
224 | dc = dc_head; | 243 | dc = dc_head; |
225 | } | 244 | } |
226 | if (NULL != peerstore_op) | 245 | if (NULL != peerstore_op) |
@@ -384,6 +403,70 @@ disconnect_peers (struct PeerInfo *p1, struct PeerInfo *p2) | |||
384 | /**************************** END DISCONNECT PEERS ***************************/ | 403 | /**************************** END DISCONNECT PEERS ***************************/ |
385 | /*****************************************************************************/ | 404 | /*****************************************************************************/ |
386 | 405 | ||
406 | /*****************************************************************************/ | ||
407 | /******************************* CONNECT PEERS *******************************/ | ||
408 | /*****************************************************************************/ | ||
409 | |||
410 | /** | ||
411 | * Callback to be called when overlay connection operation is completed | ||
412 | * | ||
413 | * @param cls the callback closure from functions generating an operation | ||
414 | * @param op the operation that has been finished | ||
415 | * @param emsg error message in case the operation has failed; will be NULL if | ||
416 | * operation has executed successfully. | ||
417 | */ | ||
418 | static void | ||
419 | overlay_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
420 | const char *emsg) | ||
421 | { | ||
422 | struct ConnectionContext *cc = cls; | ||
423 | |||
424 | if (NULL != emsg) | ||
425 | { | ||
426 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR: %s.\n", emsg); | ||
427 | GNUNET_assert (0); | ||
428 | } | ||
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer connection request sent: %d,%d\n", | ||
430 | cc->p1->index, cc->p2->index); | ||
431 | GNUNET_free (cc); | ||
432 | GNUNET_TESTBED_operation_done (op); | ||
433 | } | ||
434 | |||
435 | |||
436 | /** | ||
437 | * Connect two peers together | ||
438 | */ | ||
439 | static void | ||
440 | connect_peers (struct PeerInfo *p1, struct PeerInfo *p2) | ||
441 | { | ||
442 | struct DisconnectionContext *dc; | ||
443 | struct ConnectionContext *cc; | ||
444 | |||
445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connect_peers()\n"); | ||
446 | /* Check if we have a disconnection request before */ | ||
447 | dc = dc_head; | ||
448 | while (NULL != dc) | ||
449 | { | ||
450 | if ((dc->p1 == p1 && dc->p2 == p2) || (dc->p1 == p2 && dc->p2 == p1)) | ||
451 | break; | ||
452 | dc = dc_head->next; | ||
453 | } | ||
454 | if (NULL != dc) | ||
455 | { | ||
456 | GNUNET_CONTAINER_DLL_remove (dc_head, dc_tail, dc); | ||
457 | destroy_dc (dc); | ||
458 | } | ||
459 | /* Connect peers using testbed */ | ||
460 | cc = GNUNET_new (struct ConnectionContext); | ||
461 | cc->p1 = p1; | ||
462 | cc->p2 = p2; | ||
463 | GNUNET_TESTBED_overlay_connect (cc, &overlay_connect_cb, cc, | ||
464 | p1->testbed_peer, p2->testbed_peer); | ||
465 | } | ||
466 | |||
467 | /*****************************************************************************/ | ||
468 | /****************************** END CONNECT PEERS ****************************/ | ||
469 | /*****************************************************************************/ | ||
387 | 470 | ||
388 | /** | 471 | /** |
389 | * Function called with each file/folder inside a directory that is being copied. | 472 | * Function called with each file/folder inside a directory that is being copied. |
@@ -630,6 +713,35 @@ peerstore_disconnect_adapter (void *cls, void *op_result) | |||
630 | 713 | ||
631 | 714 | ||
632 | /** | 715 | /** |
716 | * Prompty the user to reconnect two peers | ||
717 | */ | ||
718 | static void | ||
719 | prompt_peer_reconnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
720 | { | ||
721 | int p1; | ||
722 | int p2; | ||
723 | char line[10]; | ||
724 | |||
725 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
726 | "Connect peers (e.g. '0,2') or empty line to execute:\n"); | ||
727 | if (NULL == fgets (line, sizeof (line), stdin) || 1 == strlen (line)) | ||
728 | { | ||
729 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Continuing.\n"); | ||
730 | return; | ||
731 | } | ||
732 | if (2 != sscanf (line, "%d,%d", &p1, &p2) || p1 >= num_peers || | ||
733 | p2 >= num_peers || p1 < 0 || p2 < 0 || p1 == p2) | ||
734 | { | ||
735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Invalid input.\n"); | ||
736 | prompt_peer_reconnection (NULL, NULL); | ||
737 | return; | ||
738 | } | ||
739 | connect_peers (&all_peers_info[p1], &all_peers_info[p2]); | ||
740 | prompt_peer_reconnection (NULL, NULL); | ||
741 | } | ||
742 | |||
743 | |||
744 | /** | ||
633 | * Prompt the user to disconnect two peers | 745 | * Prompt the user to disconnect two peers |
634 | */ | 746 | */ |
635 | static void | 747 | static void |
@@ -643,7 +755,8 @@ prompt_peer_disconnection () | |||
643 | "Disconnect peers (e.g. '0,2') or empty line to execute:\n"); | 755 | "Disconnect peers (e.g. '0,2') or empty line to execute:\n"); |
644 | if (NULL == fgets (line, sizeof (line), stdin) || 1 == strlen (line)) | 756 | if (NULL == fgets (line, sizeof (line), stdin) || 1 == strlen (line)) |
645 | { | 757 | { |
646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Continuing.\n"); | 758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will prompt for reconnection in 1 min.\n"); |
759 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) ,&prompt_peer_reconnection, NULL); | ||
647 | return; | 760 | return; |
648 | } | 761 | } |
649 | if (2 != sscanf (line, "%d,%d", &p1, &p2) || p1 >= num_peers || | 762 | if (2 != sscanf (line, "%d,%d", &p1, &p2) || p1 >= num_peers || |
diff --git a/src/sensor/gnunet-service-sensor_analysis.c b/src/sensor/gnunet-service-sensor_analysis.c index d9ca48dd0..b82db4b8e 100644 --- a/src/sensor/gnunet-service-sensor_analysis.c +++ b/src/sensor/gnunet-service-sensor_analysis.c | |||
@@ -213,7 +213,8 @@ sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | |||
213 | { | 213 | { |
214 | model->anomalous = GNUNET_YES; | 214 | model->anomalous = GNUNET_YES; |
215 | LOG (GNUNET_ERROR_TYPE_WARNING, | 215 | LOG (GNUNET_ERROR_TYPE_WARNING, |
216 | "Anomaly state started for sensor `%s'.\n", model->sensor->name); | 216 | "Anomaly state started for sensor `%s', value: %f.\n", |
217 | model->sensor->name, val); | ||
217 | SENSOR_reporting_anomaly_update (model->sensor, model->anomalous); | 218 | SENSOR_reporting_anomaly_update (model->sensor, model->anomalous); |
218 | } | 219 | } |
219 | } | 220 | } |
@@ -225,8 +226,9 @@ sensor_watcher (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | |||
225 | model->negative_count >= confirmation_count) | 226 | model->negative_count >= confirmation_count) |
226 | { | 227 | { |
227 | model->anomalous = GNUNET_NO; | 228 | model->anomalous = GNUNET_NO; |
228 | LOG (GNUNET_ERROR_TYPE_INFO, "Anomaly state stopped for sensor `%s'.\n", | 229 | LOG (GNUNET_ERROR_TYPE_INFO, |
229 | model->sensor->name); | 230 | "Anomaly state stopped for sensor `%s', value: %f.\n", |
231 | model->sensor->name, val); | ||
230 | SENSOR_reporting_anomaly_update (model->sensor, model->anomalous); | 232 | SENSOR_reporting_anomaly_update (model->sensor, model->anomalous); |
231 | } | 233 | } |
232 | } | 234 | } |