[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11532 - in gnunet/src: include testing
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11532 - in gnunet/src: include testing |
Date: |
Thu, 27 May 2010 12:43:18 +0200 |
Author: grothoff
Date: 2010-05-27 12:43:18 +0200 (Thu, 27 May 2010)
New Revision: 11532
Modified:
gnunet/src/include/gnunet_testing_lib.h
gnunet/src/testing/testing.c
gnunet/src/testing/testing_group.c
Log:
api for controlled churn
Modified: gnunet/src/include/gnunet_testing_lib.h
===================================================================
--- gnunet/src/include/gnunet_testing_lib.h 2010-05-27 09:35:24 UTC (rev
11531)
+++ gnunet/src/include/gnunet_testing_lib.h 2010-05-27 10:43:18 UTC (rev
11532)
@@ -546,11 +546,12 @@
*
* @param pg handle to the peer group
* @param timeout how long to wait for shutdown
- *
*/
void
-GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, struct
GNUNET_TIME_Relative timeout);
+GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
+ struct GNUNET_TIME_Relative timeout);
+
/**
* Simulate churn by stopping some peers (and possibly
* re-starting others if churn is called multiple times). This
@@ -715,6 +716,25 @@
double option_modifier);
/**
+ * Start or stop an individual peer from the given group.
+ *
+ * @param pg handle to the peer group
+ * @param offset which peer to start or stop
+ * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it
+ * @param timeout how long to wait for shutdown
+ * @param cb function to call at the end
+ * @param cb_cls closure for cb
+ */
+void
+GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
+ unsigned int offset,
+ int desired_status,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyCompletion cb,
+ void *cb_cls);
+
+
+/**
* Start "count" GNUnet daemons with a particular topology.
*
* @param sched scheduler to use
Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c 2010-05-27 09:35:24 UTC (rev 11531)
+++ gnunet/src/testing/testing.c 2010-05-27 10:43:18 UTC (rev 11532)
@@ -922,7 +922,8 @@
GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
- int delete_files, int allow_restart)
+ int delete_files,
+ int allow_restart)
{
char *arg;
char *del_arg;
@@ -960,13 +961,10 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
#endif
-
d->phase = SP_SHUTDOWN_START;
d->running = GNUNET_NO;
-
if (allow_restart == GNUNET_YES)
d->churn = GNUNET_YES;
-
if (d->th != NULL)
{
GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d);
@@ -993,7 +991,6 @@
#endif
"-c", d->cfgfile, "-e", "-q", del_arg,
NULL);
/* Use -e to end arm, and -d to remove temp files */
-
GNUNET_free (arg);
}
else
Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c 2010-05-27 09:35:24 UTC (rev 11531)
+++ gnunet/src/testing/testing_group.c 2010-05-27 10:43:18 UTC (rev 11532)
@@ -2698,17 +2698,20 @@
error_message = NULL;
if (emsg != NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Churn stop callback failed with
error `%s'\n", emsg);
- churn_ctx->num_failed_stop++;
- }
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+ "Churn stop callback failed with error `%s'\n", emsg);
+ churn_ctx->num_failed_stop++;
+ }
else
- {
- churn_ctx->num_to_stop--;
- }
+ {
+ churn_ctx->num_to_stop--;
+ }
#if DEBUG_CHURN
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopped peer, %d left.\n",
churn_ctx->num_to_stop);
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+ "Stopped peer, %d left.\n",
+ churn_ctx->num_to_stop);
#endif
total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) +
(churn_ctx->num_to_start - churn_ctx->num_failed_start);
@@ -2716,7 +2719,10 @@
{
if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
{
- GNUNET_asprintf(&error_message, "Churn didn't complete successfully,
%u peers failed to start %u peers failed to be stopped!",
churn_ctx->num_failed_start, churn_ctx->num_failed_stop);
+ GNUNET_asprintf(&error_message,
+ "Churn didn't complete successfully, %u peers failed to
start %u peers failed to be stopped!",
+ churn_ctx->num_failed_start,
+ churn_ctx->num_failed_stop);
}
churn_ctx->cb(churn_ctx->cb_cls, error_message);
GNUNET_free_non_null(error_message);
@@ -2748,17 +2754,21 @@
error_message = NULL;
if (emsg != NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Churn stop callback failed with
error `%s'\n", emsg);
- churn_ctx->num_failed_start++;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Churn stop callback failed with error `%s'\n",
+ emsg);
+ churn_ctx->num_failed_start++;
+ }
else
- {
- churn_ctx->num_to_start--;
- }
-
+ {
+ churn_ctx->num_to_start--;
+ }
+
#if DEBUG_CHURN
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Started peer, %d left.\n",
churn_ctx->num_to_start);
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+ "Started peer, %d left.\n",
+ churn_ctx->num_to_start);
#endif
total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) +
(churn_ctx->num_to_start - churn_ctx->num_failed_start);
@@ -2766,14 +2776,17 @@
if (total_left == 0)
{
if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
- GNUNET_asprintf(&error_message, "Churn didn't complete successfully, %u
peers failed to start %u peers failed to be stopped!",
churn_ctx->num_failed_start, churn_ctx->num_failed_stop);
+ GNUNET_asprintf(&error_message,
+ "Churn didn't complete successfully, %u peers failed to
start %u peers failed to be stopped!",
+ churn_ctx->num_failed_start,
+ churn_ctx->num_failed_stop);
churn_ctx->cb(churn_ctx->cb_cls, error_message);
GNUNET_free_non_null(error_message);
GNUNET_free(churn_ctx);
}
-
}
+
/**
* Simulate churn by stopping some peers (and possibly
* re-starting others if churn is called multiple times). This
@@ -2885,15 +2898,19 @@
#if DEBUG_CHURN
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n",
running_permute[i]);
#endif
-
GNUNET_TESTING_daemon_stop(pg->peers[running_arr[running_permute[i]]].daemon,
timeout, &churn_stop_callback, churn_ctx, GNUNET_NO, GNUNET_YES);
+ GNUNET_TESTING_daemon_stop
(pg->peers[running_arr[running_permute[i]]].daemon,
+ timeout,
+ &churn_stop_callback, churn_ctx,
+ GNUNET_NO, GNUNET_YES);
}
for (i = 0; i < von; i++)
- {
+ {
#if DEBUG_CHURN
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n",
stopped_permute[i]);
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n",
stopped_permute[i]);
#endif
-
GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon,
timeout, &churn_start_callback, churn_ctx);
+
GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon,
+ timeout, &churn_start_callback,
churn_ctx);
}
GNUNET_free(running_arr);
@@ -2932,36 +2949,85 @@
}
/**
+ * Start or stop an individual peer from the given group.
+ *
+ * @param pg handle to the peer group
+ * @param offset which peer to start or stop
+ * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it
+ * @param timeout how long to wait for shutdown
+ * @param cb function to call at the end
+ * @param cb_cls closure for cb
+ */
+void
+GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
+ unsigned int offset,
+ int desired_status,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyCompletion cb,
+ void *cb_cls)
+{
+ struct ChurnContext *churn_ctx;
+
+ if (GNUNET_NO == desired_status)
+ {
+ if (NULL != pg->peers[offset].daemon)
+ {
+ churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext));
+ churn_ctx->num_to_start = 0;
+ churn_ctx->num_to_stop = 1;
+ churn_ctx->cb = cb;
+ churn_ctx->cb_cls = cb_cls;
+ GNUNET_TESTING_daemon_stop(pg->peers[offset].daemon,
+ timeout, &churn_stop_callback, churn_ctx,
+ GNUNET_NO, GNUNET_YES);
+ }
+ }
+ else if (GNUNET_YES == desired_status)
+ {
+ if (NULL == pg->peers[offset].daemon)
+ {
+ churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext));
+ churn_ctx->num_to_start = 1;
+ churn_ctx->num_to_stop = 0;
+ churn_ctx->cb = cb;
+ churn_ctx->cb_cls = cb_cls;
+ GNUNET_TESTING_daemon_start_stopped(pg->peers[offset].daemon,
+ timeout, &churn_start_callback,
churn_ctx);
+ }
+ }
+ else
+ GNUNET_break (0);
+}
+
+
+/**
* Shutdown all peers started in the given group.
*
* @param pg handle to the peer group
* @param timeout how long to wait for shutdown
- *
*/
void
-GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, struct
GNUNET_TIME_Relative timeout)
+GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
+ struct GNUNET_TIME_Relative timeout)
{
unsigned int off;
for (off = 0; off < pg->total; off++)
{
- /* FIXME: should we wait for our
- continuations to be called here? This
- would require us to take a continuation
- as well... */
+ /* FIXME: should we wait for our continuations to be called
+ here? This would require us to take a continuation as
+ well... */
if (NULL != pg->peers[off].daemon)
GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL,
NULL, GNUNET_YES, GNUNET_NO);
if (NULL != pg->peers[off].cfg)
GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);
-
if (pg->peers[off].allowed_peers != NULL)
GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].allowed_peers);
if (pg->peers[off].connect_peers != NULL)
GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].connect_peers);
if (pg->peers[off].blacklisted_peers != NULL)
GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].blacklisted_peers);
-
}
GNUNET_free (pg->peers);
if (NULL != pg->hosts)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11532 - in gnunet/src: include testing,
gnunet <=