diff options
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r-- | src/testing/testing_group.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 7986d1b5f..ba4b29150 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -279,6 +279,33 @@ struct PeerRestartContext | |||
279 | struct GNUNET_TESTING_Daemon *daemon; | 279 | struct GNUNET_TESTING_Daemon *daemon; |
280 | }; | 280 | }; |
281 | 281 | ||
282 | struct ServiceStartContext | ||
283 | { | ||
284 | struct GNUNET_TESTING_PeerGroup *pg; | ||
285 | unsigned int remaining; | ||
286 | GNUNET_TESTING_NotifyCompletion cb; | ||
287 | unsigned int outstanding; | ||
288 | char *service; | ||
289 | struct GNUNET_TIME_Relative timeout; | ||
290 | void *cb_cls; | ||
291 | }; | ||
292 | |||
293 | /** | ||
294 | * Individual shutdown context for a particular peer. | ||
295 | */ | ||
296 | struct PeerServiceStartContext | ||
297 | { | ||
298 | /** | ||
299 | * Pointer to the high level start context. | ||
300 | */ | ||
301 | struct ServiceStartContext *start_ctx; | ||
302 | |||
303 | /** | ||
304 | * The daemon handle for the peer to start the service on. | ||
305 | */ | ||
306 | struct GNUNET_TESTING_Daemon *daemon; | ||
307 | }; | ||
308 | |||
282 | struct CreateTopologyContext | 309 | struct CreateTopologyContext |
283 | { | 310 | { |
284 | 311 | ||
@@ -5605,6 +5632,66 @@ schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5605 | } | 5632 | } |
5606 | } | 5633 | } |
5607 | 5634 | ||
5635 | /** | ||
5636 | * Callback for informing us about a successful | ||
5637 | * or unsuccessful churn start call. | ||
5638 | * | ||
5639 | * @param cls a struct ServiceStartContext *startup_ctx | ||
5640 | * @param id the peer identity of the started peer | ||
5641 | * @param cfg the handle to the configuration of the peer | ||
5642 | * @param d handle to the daemon for the peer | ||
5643 | * @param emsg NULL on success, non-NULL on failure | ||
5644 | * | ||
5645 | */ | ||
5646 | void | ||
5647 | service_start_callback(void *cls, | ||
5648 | const struct GNUNET_PeerIdentity *id, | ||
5649 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
5650 | struct GNUNET_TESTING_Daemon *d, | ||
5651 | const char *emsg) | ||
5652 | { | ||
5653 | struct ServiceStartContext *startup_ctx = (struct ServiceStartContext *)cls; | ||
5654 | |||
5655 | if (emsg != NULL) | ||
5656 | { | ||
5657 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
5658 | "Service start failed with error `%s'\n", emsg); | ||
5659 | } | ||
5660 | |||
5661 | startup_ctx->outstanding--; | ||
5662 | startup_ctx->remaining--; | ||
5663 | |||
5664 | if (startup_ctx->remaining == 0) | ||
5665 | { | ||
5666 | startup_ctx->cb (startup_ctx->cb_cls, NULL); | ||
5667 | GNUNET_free (startup_ctx->service); | ||
5668 | GNUNET_free (startup_ctx); | ||
5669 | } | ||
5670 | } | ||
5671 | |||
5672 | static void | ||
5673 | schedule_service_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
5674 | { | ||
5675 | struct PeerServiceStartContext *peer_ctx = cls; | ||
5676 | struct ServiceStartContext *startup_ctx = peer_ctx->start_ctx; | ||
5677 | |||
5678 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) | ||
5679 | GNUNET_SCHEDULER_add_delayed ( | ||
5680 | GNUNET_TIME_relative_multiply ( | ||
5681 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
5682 | 100), | ||
5683 | &schedule_service_start, peer_ctx); | ||
5684 | else | ||
5685 | { | ||
5686 | |||
5687 | GNUNET_TESTING_daemon_start_service (peer_ctx->daemon, | ||
5688 | startup_ctx->service, | ||
5689 | startup_ctx->timeout, | ||
5690 | &service_start_callback, startup_ctx); | ||
5691 | GNUNET_free (peer_ctx); | ||
5692 | } | ||
5693 | } | ||
5694 | |||
5608 | 5695 | ||
5609 | static void | 5696 | static void |
5610 | internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5697 | internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -6635,6 +6722,48 @@ GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg, | |||
6635 | GNUNET_free_non_null (stopped_permute); | 6722 | GNUNET_free_non_null (stopped_permute); |
6636 | } | 6723 | } |
6637 | 6724 | ||
6725 | /* | ||
6726 | * Start a given service for each of the peers in the peer group. | ||
6727 | * | ||
6728 | * @param pg handle for the peer group | ||
6729 | * @param service the service to start | ||
6730 | * @param timeout how long to wait for operations to finish before | ||
6731 | * giving up | ||
6732 | * @param cb function to call once finished | ||
6733 | * @param cb_cls closure for cb | ||
6734 | * | ||
6735 | */ | ||
6736 | void | ||
6737 | GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg, | ||
6738 | char *service, | ||
6739 | struct GNUNET_TIME_Relative timeout, | ||
6740 | GNUNET_TESTING_NotifyCompletion cb, | ||
6741 | void *cb_cls) | ||
6742 | { | ||
6743 | struct ServiceStartContext *start_ctx; | ||
6744 | struct PeerServiceStartContext *peer_start_ctx; | ||
6745 | unsigned int i; | ||
6746 | |||
6747 | GNUNET_assert(service != NULL); | ||
6748 | |||
6749 | start_ctx = GNUNET_malloc(sizeof(struct ServiceStartContext)); | ||
6750 | start_ctx->pg = pg; | ||
6751 | start_ctx->remaining = pg->total; | ||
6752 | start_ctx->cb = cb; | ||
6753 | start_ctx->cb_cls = cb_cls; | ||
6754 | start_ctx->service = GNUNET_strdup(service); | ||
6755 | |||
6756 | for (i = 0; i < pg->total; i++) | ||
6757 | { | ||
6758 | #if DEBUG_START | ||
6759 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up service %s on peer %d!\n", service, stopped_arr[stopped_permute[i]]); | ||
6760 | #endif | ||
6761 | peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext)); | ||
6762 | peer_start_ctx->start_ctx = start_ctx; | ||
6763 | peer_start_ctx->daemon = pg->peers[i].daemon; | ||
6764 | GNUNET_SCHEDULER_add_now (&schedule_service_start, peer_start_ctx); | ||
6765 | } | ||
6766 | } | ||
6638 | 6767 | ||
6639 | /** | 6768 | /** |
6640 | * Restart all peers in the given group. | 6769 | * Restart all peers in the given group. |