aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-05-07 14:35:46 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-05-07 14:35:46 +0000
commit05aa8d8001e3977adb5d68d851db608c075dffee (patch)
tree2c4e23e307a917d67fb41719f2b858bccea590aa
parent3029a328070bd5eb422261fb3559b01f415ae51c (diff)
fix #2665: peer reconfiguration now implemented
-rw-r--r--src/testbed/Makefile.am8
-rw-r--r--src/testbed/gnunet-service-testbed.c4
-rw-r--r--src/testbed/gnunet-service-testbed.h21
-rw-r--r--src/testbed/gnunet-service-testbed_peers.c340
-rw-r--r--src/testbed/test_testbed_api_peer_reconfiguration.c192
-rw-r--r--src/testbed/testbed.h17
-rw-r--r--src/testbed/testbed_api.c33
-rw-r--r--src/testbed/testbed_api.h5
-rw-r--r--src/testbed/testbed_api_peers.c102
-rw-r--r--src/testbed/testbed_api_peers.h22
10 files changed, 685 insertions, 59 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 43435bf9ef..3f3d6db550 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -132,6 +132,7 @@ check_PROGRAMS = \
test_testbed_api_testbed_run \
test_testbed_api_test \
test_testbed_api_test_timeout \
+ test_testbed_api_peer_reconfiguration \
test_testbed_api_peers_manage_services \
test_testbed_api_topology \
test_testbed_api_topology_clique \
@@ -162,6 +163,7 @@ if ENABLE_TEST_RUN
test_testbed_api_test \
test_testbed_api_test_timeout \
test_testbed_api_statistics \
+ test_testbed_api_peer_reconfiguration \
test_testbed_api_peers_manage_services \
test_testbed_api_topology \
test_testbed_api_topology_clique \
@@ -338,6 +340,12 @@ test_testbed_api_peers_manage_services_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
libgnunettestbed.la
+test_testbed_api_peer_reconfiguration_SOURCES = \
+ test_testbed_api_peer_reconfiguration.c
+test_testbed_api_peer_reconfiguration_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ libgnunettestbed.la
+
EXTRA_DIST = \
test_testbed_api.conf \
test_testbed_api_test_timeout.conf \
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 6bca3d9cde..4e73680c9f 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -762,6 +762,7 @@ GST_clear_fopcq ()
case OP_LINK_CONTROLLERS:
case OP_GET_SLAVE_CONFIG:
case OP_MANAGE_SERVICE:
+ case OP_PEER_RECONFIGURE:
break;
case OP_FORWARDED:
GNUNET_assert (0);
@@ -793,6 +794,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GST_free_roccq ();
GST_free_nccq ();
GST_neighbour_list_clean();
+ GST_free_prcq ();
/* Clear peer list */
GST_destroy_peers ();
/* Clear route list */
@@ -895,6 +897,8 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
{&GST_handle_shutdown_peers, NULL, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS,
sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)},
+ {&GST_handle_peer_reconfigure, NULL,
+ GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 0},
{NULL, NULL, 0, 0}
};
char *logfile;
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h
index bdf0f4ccef..55ad084219 100644
--- a/src/testbed/gnunet-service-testbed.h
+++ b/src/testbed/gnunet-service-testbed.h
@@ -717,6 +717,20 @@ GST_handle_manage_peer_service (void *cls, struct GNUNET_SERVER_Client *client,
/**
+ * Handler for GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages.
+ * Should stop the peer asyncronously, destroy it and create it again with the
+ * new configuration.
+ *
+ * @param cls NULL
+ * @param client identification of the client
+ * @param message the actual message
+ */
+void
+GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message);
+
+
+/**
* Frees the ManageServiceContext queue
*/
void
@@ -770,6 +784,13 @@ GST_free_roccq ();
/**
+ * Cleans up the Peer reconfigure context list
+ */
+void
+GST_free_prcq ();
+
+
+/**
* Initializes the cache
*
* @param size the size of the cache
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c
index 3de4af03af..34c1bf085b 100644
--- a/src/testbed/gnunet-service-testbed_peers.c
+++ b/src/testbed/gnunet-service-testbed_peers.c
@@ -85,6 +85,61 @@ struct ManageServiceContext
/**
+ * Context information for peer re-configure operations
+ */
+struct PeerReconfigureContext
+{
+ /**
+ * DLL next for inclusoin in peer reconfigure operations list
+ */
+ struct PeerReconfigureContext *next;
+
+ /**
+ * DLL prev
+ */
+ struct PeerReconfigureContext *prev;
+
+ /**
+ * The client which gave this operation to us
+ */
+ struct GNUNET_SERVER_Client *client;
+
+ /**
+ * The configuration handle to use as the new template
+ */
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * The id of the operation
+ */
+ uint64_t op_id;
+
+ /**
+ * The id of the peer which has to be reconfigured
+ */
+ uint32_t peer_id;
+
+ /**
+ * The the peer stopped? Used while cleaning up this context to decide
+ * whether the asynchronous stop request through Testing/ARM API has to be
+ * cancelled
+ */
+ uint8_t stopped;
+};
+
+/**
+ * The DLL head for the peer reconfigure list
+ */
+static struct PeerReconfigureContext *prc_head;
+
+/**
+ * The DLL tail for the peer reconfigure list
+ */
+static struct PeerReconfigureContext *prc_tail;
+
+
+
+/**
* DLL head for queue of manage service requests
*/
static struct ManageServiceContext *mctx_head;
@@ -253,10 +308,7 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
struct ForwardedOperationContext *fo_ctxt;
struct Route *route;
struct Peer *peer;
- char *config;
- size_t dest_size;
- int ret;
- uint32_t config_size;
+ char *emsg;
uint32_t host_id;
uint32_t peer_id;
uint16_t msize;
@@ -272,8 +324,17 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
host_id = ntohl (msg->host_id);
peer_id = ntohl (msg->peer_id);
- if (UINT32_MAX == peer_id)
+ if (VALID_PEER_ID (peer_id))
{
+ (void) GNUNET_asprintf (&emsg, "Peer with ID %u already exists", peer_id);
+ GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
+ emsg);
+ GNUNET_free (emsg);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+ if (UINT32_MAX == peer_id)
+ {
GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
"Cannot create peer with given ID");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -281,39 +342,14 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
}
if (host_id == GST_context->host_id)
{
- char *emsg;
-
/* We are responsible for this peer */
- msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
- config_size = ntohl (msg->config_size);
- config = GNUNET_malloc (config_size);
- dest_size = config_size;
- if (Z_OK !=
- (ret =
- uncompress ((Bytef *) config, (uLongf *) & dest_size,
- (const Bytef *) &msg[1], (uLong) msize)))
- {
- GNUNET_break (0); /* uncompression error */
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- if (config_size != dest_size)
- {
- GNUNET_break (0); /* Uncompressed config size mismatch */
- GNUNET_free (config);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
+ cfg = GNUNET_TESTBED_extract_config_ (message);
+ if (NULL == cfg)
{
- GNUNET_break (0); /* Configuration parsing error */
- GNUNET_free (config);
+ GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_free (config);
GNUNET_CONFIGURATION_set_value_number (cfg, "TESTBED", "PEERID",
(unsigned long long) peer_id);
peer = GNUNET_malloc (sizeof (struct Peer));
@@ -359,7 +395,6 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
-
peer = GNUNET_malloc (sizeof (struct Peer));
peer->is_remote = GNUNET_YES;
peer->id = peer_id;
@@ -369,7 +404,7 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_SERVER_client_keep (client);
fo_ctxt->client = client;
fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
- fo_ctxt->cls = peer; //GST_slave_list[route->dest]->controller;
+ fo_ctxt->cls = peer;
fo_ctxt->type = OP_PEER_CREATE;
fo_ctxt->opc =
GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list
@@ -405,7 +440,7 @@ GST_handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
peer_id = ntohl (msg->peer_id);
LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
peer_id, GNUNET_ntohll (msg->operation_id));
- if ((GST_peer_list_size <= peer_id) || (NULL == GST_peer_list[peer_id]))
+ if (!VALID_PEER_ID (peer_id))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Asked to destroy a non existent peer with id: %u\n", peer_id);
@@ -448,6 +483,40 @@ GST_handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
/**
+ * Stats a peer
+ *
+ * @param peer the peer to start
+ * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
+ */
+static int
+start_peer (struct Peer *peer)
+{
+ GNUNET_assert (GNUNET_NO == peer->is_remote);
+ if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
+ return GNUNET_SYSERR;
+ peer->details.local.is_running = GNUNET_YES;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Stops a peer
+ *
+ * @param peer the peer to stop
+ * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
+ */
+static int
+stop_peer (struct Peer *peer)
+{
+ GNUNET_assert (GNUNET_NO == peer->is_remote);
+ if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer))
+ return GNUNET_SYSERR;
+ peer->details.local.is_running = GNUNET_NO;
+ return GNUNET_OK;
+}
+
+
+/**
* Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
*
* @param cls NULL
@@ -466,7 +535,7 @@ GST_handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
peer_id = ntohl (msg->peer_id);
- if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
+ if (!VALID_PEER_ID (peer_id))
{
GNUNET_break (0);
LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -495,14 +564,13 @@ GST_handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
- if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
+ if (GNUNET_OK != start_peer (peer))
{
GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
"Failed to start");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
- peer->details.local.is_running = GNUNET_YES;
reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
@@ -535,7 +603,7 @@ GST_handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
peer_id = ntohl (msg->peer_id);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PEER_STOP for peer %u\n", peer_id);
- if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
+ if (!VALID_PEER_ID (peer_id))
{
GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
"Peer not found");
@@ -565,7 +633,7 @@ GST_handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
- if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer))
+ if (GNUNET_OK != stop_peer (peer))
{
LOG (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %u failed\n", peer_id);
GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
@@ -574,7 +642,6 @@ GST_handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %u successfully stopped\n", peer_id);
- peer->details.local.is_running = GNUNET_NO;
reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
@@ -601,6 +668,7 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
{
const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
+ struct ForwardedOperationContext *fopc;
struct Peer *peer;
char *config;
char *xconfig;
@@ -611,7 +679,8 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
peer_id = ntohl (msg->peer_id);
- if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
+ LOG_DEBUG ("Received GET_CONFIG for peer %u\n", peer_id);
+ if (!VALID_PEER_ID (peer_id))
{
GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
"Peer not found");
@@ -621,8 +690,6 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
peer = GST_peer_list[peer_id];
if (GNUNET_YES == peer->is_remote)
{
- struct ForwardedOperationContext *fopc;
-
LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", peer_id);
fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
GNUNET_SERVER_client_keep (client);
@@ -666,6 +733,189 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
/**
+ * Cleans up the given PeerReconfigureContext
+ *
+ * @param prc the PeerReconfigureContext
+ */
+static void
+cleanup_prc (struct PeerReconfigureContext *prc)
+{
+ struct Peer *peer;
+
+ if (VALID_PEER_ID (prc->peer_id))
+ {
+ peer = GST_peer_list [prc->peer_id];
+ if (1 != prc->stopped)
+ {
+ GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer);
+ stop_peer (peer); /* Stop the peer synchronously */
+ }
+ }
+ if (NULL != prc->cfg)
+ GNUNET_CONFIGURATION_destroy (prc->cfg);
+ GNUNET_SERVER_client_drop (prc->client);
+ GNUNET_CONTAINER_DLL_remove (prc_head, prc_tail, prc);
+ GNUNET_free (prc);
+}
+
+
+/**
+ * Cleans up the Peer reconfigure context list
+ */
+void
+GST_free_prcq ()
+{
+ while (NULL != prc_head)
+ cleanup_prc (prc_head);
+}
+
+
+/**
+ * Callback to inform whether the peer is running or stopped.
+ *
+ * @param cls the closure given to GNUNET_TESTING_peer_stop_async()
+ * @param peer the respective peer whose status is being reported
+ * @param success GNUNET_YES if the peer is stopped; GNUNET_SYSERR upon any
+ * error
+ */
+static void
+prc_stop_cb (void *cls, struct GNUNET_TESTING_Peer *p, int success)
+{
+ struct PeerReconfigureContext *prc = cls;
+ struct Peer *peer;
+ char *emsg;
+
+ GNUNET_assert (VALID_PEER_ID (prc->peer_id));
+ peer = GST_peer_list [prc->peer_id];
+ GNUNET_assert (GNUNET_NO == peer->is_remote);
+ GNUNET_TESTING_peer_destroy (peer->details.local.peer);
+ GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
+ peer->details.local.cfg = prc->cfg;
+ prc->cfg = NULL;
+ prc->stopped = 1;
+ emsg = NULL;
+ peer->details.local.peer
+ = GNUNET_TESTING_peer_configure (GST_context->system,
+ peer->details.local.cfg, peer->id,
+ NULL /* Peer id */ ,
+ &emsg);
+ if (NULL == peer->details.local.peer)
+ {
+ GST_send_operation_fail_msg (prc->client, prc->op_id, emsg);
+ goto cleanup;
+ }
+ if (GNUNET_OK != start_peer (peer))
+ {
+
+ GST_send_operation_fail_msg (prc->client, prc->op_id,
+ "Failed to start reconfigured peer");
+ goto cleanup;
+ }
+ GST_send_operation_success_msg (prc->client, prc->op_id);
+
+ cleanup:
+ cleanup_prc (prc);
+ return;
+}
+
+
+/**
+ * Handler for GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages.
+ * Should stop the peer asyncronously, destroy it and create it again with the
+ * new configuration.
+ *
+ * @param cls NULL
+ * @param client identification of the client
+ * @param message the actual message
+ */
+void
+GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ const struct GNUNET_TESTBED_PeerReconfigureMessage *msg;
+ struct Peer *peer;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct ForwardedOperationContext *fopc;
+ struct PeerReconfigureContext *prc;
+ uint64_t op_id;
+ uint32_t peer_id;
+ uint16_t msize;
+
+ msize = ntohs (message->size);
+ if (msize <= sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage))
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ msg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) message;
+ peer_id = ntohl (msg->peer_id);
+ op_id = GNUNET_ntohll (msg->operation_id);
+ if (!VALID_PEER_ID (peer_id))
+ {
+ GNUNET_break (0);
+ GST_send_operation_fail_msg (client, op_id, "Peer not found");
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+ peer = GST_peer_list[peer_id];
+ if (GNUNET_YES == peer->is_remote)
+ {
+ LOG_DEBUG ("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id);
+ fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
+ GNUNET_SERVER_client_keep (client);
+ fopc->client = client;
+ fopc->operation_id = op_id;
+ fopc->type = OP_PEER_RECONFIGURE;
+ fopc->opc =
+ GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
+ slave->controller,
+ fopc->operation_id, &msg->header,
+ &GST_forwarded_operation_reply_relay,
+ fopc);
+ fopc->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
+ fopc);
+ GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+ LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n", peer_id);
+ if (0 < peer->reference_cnt)
+ {
+ GNUNET_break (0);
+ GST_send_operation_fail_msg (client, op_id, "Peer in use");
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+ if (GNUNET_YES == peer->destroy_flag)
+ {
+ GNUNET_break (0);
+ GST_send_operation_fail_msg (client, op_id, "Peer is being destroyed");
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+ cfg = GNUNET_TESTBED_extract_config_ (message);
+ if (NULL == cfg)
+ {
+ GNUNET_break (0);
+ GST_send_operation_fail_msg (client, op_id, "Compression error");
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+ prc = GNUNET_malloc (sizeof (struct PeerReconfigureContext));
+ prc->cfg = cfg;
+ prc->peer_id = peer_id;
+ prc->op_id = op_id;
+ prc->client = client;
+ GNUNET_SERVER_client_keep (client);
+ GNUNET_CONTAINER_DLL_insert_tail (prc_head, prc_tail, prc);
+ GNUNET_TESTING_peer_stop_async (peer->details.local.peer, prc_stop_cb, prc);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
+/**
* Cleanup the context information created for managing a peer's service
*
* @param mctx the ManageServiceContext
diff --git a/src/testbed/test_testbed_api_peer_reconfiguration.c b/src/testbed/test_testbed_api_peer_reconfiguration.c
new file mode 100644
index 0000000000..398eab85cd
--- /dev/null
+++ b/src/testbed/test_testbed_api_peer_reconfiguration.c
@@ -0,0 +1,192 @@
+/*
+ This file is part of GNUnet
+ (C) 2008--2013 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file testbed/test_testbed_api_peer_reconfiguration.c
+ * @brief testcase for testing GNUNET_TESTBED_peer_manage_service()
+ * implementation
+ * @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ */
+
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_testbed_service.h"
+
+/**
+ * Number of peers we want to start
+ */
+#define NUM_PEERS 1
+
+/**
+ * The array of peers; we get them from the testbed
+ */
+static struct GNUNET_TESTBED_Peer **peers;
+
+/**
+ * Operation handle
+ */
+static struct GNUNET_TESTBED_Operation *op;
+
+/**
+ * Abort task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier abort_task;
+
+/**
+ * States in this test
+ */
+enum {
+
+ /**
+ * Test has just been initialized
+ */
+ STATE_INIT,
+
+ /**
+ * Peers have been started
+ */
+ STATE_PEER_STARTED,
+
+ /**
+ * Peer has been reconfigured. Test completed successfully
+ */
+ STATE_PEER_RECONFIGURED
+
+} state;
+
+/**
+ * Fail testcase
+ */
+#define FAIL_TEST(cond, ret) do { \
+ if (!(cond)) { \
+ GNUNET_break(0); \
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task) \
+ GNUNET_SCHEDULER_cancel (abort_task); \
+ abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
+ ret; \
+ } \
+ } while (0)
+
+
+/**
+ * Abort task
+ *
+ * @param cls NULL
+ * @param tc scheduler task context
+ */
+static void
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n");
+ abort_task = GNUNET_SCHEDULER_NO_TASK;
+ if (NULL != op)
+ {
+ GNUNET_TESTBED_operation_done (op);
+ op = NULL;
+ }
+ GNUNET_SCHEDULER_shutdown();
+}
+
+
+/**
+ * Signature of the event handler function called by the
+ * respective event controller.
+ *
+ * @param cls closure
+ * @param event information about the event
+ */
+static void
+controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
+{
+ if (STATE_PEER_STARTED != state)
+ return;
+ if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
+ {
+ GNUNET_TESTBED_operation_done (op);
+ op = NULL;
+ FAIL_TEST (0, return);
+ }
+ if (NULL != event->details.operation_finished.emsg)
+ {
+ fprintf (stderr, "Operation failed: %s\n",
+ event->details.operation_finished.emsg);
+ GNUNET_TESTBED_operation_done (op);
+ op = NULL;
+ FAIL_TEST (0, return);
+ }
+ GNUNET_TESTBED_operation_done (op);
+ state = STATE_PEER_RECONFIGURED;
+ GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Signature of a main function for a testcase.
+ *
+ * @param cls closure
+ * @param num_peers number of peers in 'peers'
+ * @param peers_ handle to peers run in the testbed
+ * @param links_succeeded the number of overlay link connection attempts that
+ * succeeded
+ * @param links_failed the number of overlay link connection attempts that
+ * failed
+ */
+static void
+test_master (void *cls, unsigned int num_peers,
+ struct GNUNET_TESTBED_Peer **peers_,
+ unsigned int links_succeeded,
+ unsigned int links_failed)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ FAIL_TEST (NUM_PEERS == num_peers, return);
+ state = STATE_PEER_STARTED;
+ peers = peers_;
+ cfg = GNUNET_CONFIGURATION_create ();
+ FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_parse
+ (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return);
+ op = GNUNET_TESTBED_peer_update_configuration (peers[0], cfg);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ FAIL_TEST (NULL != op, return);
+ abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 30),
+ &do_abort, NULL);
+}
+
+
+/**
+ * Main function
+ */
+int
+main (int argc, char **argv)
+{
+ state = STATE_INIT;
+ (void) GNUNET_TESTBED_test_run ("test_testbed_api_peer_reconfiguration",
+ "test_testbed_api.conf",
+ NUM_PEERS,
+ 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED,
+ &controller_cb, NULL,
+ &test_master, NULL);
+ if (STATE_PEER_RECONFIGURED != state)
+ return 1;
+ return 0;
+}
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h
index ed4e27dc69..904e7acbaa 100644
--- a/src/testbed/testbed.h
+++ b/src/testbed/testbed.h
@@ -219,14 +219,14 @@ struct GNUNET_TESTBED_PeerCreateMessage
struct GNUNET_MessageHeader header;
/**
- * Unique operation id
+ * On which host should the peer be started?
*/
- uint64_t operation_id GNUNET_PACKED;
+ uint32_t host_id GNUNET_PACKED;
/**
- * On which host should the peer be started?
+ * Unique operation id
*/
- uint32_t host_id GNUNET_PACKED;
+ uint64_t operation_id GNUNET_PACKED;
/**
* Unique ID for the peer.
@@ -236,7 +236,7 @@ struct GNUNET_TESTBED_PeerCreateMessage
/**
* Size of the uncompressed configuration
*/
- uint32_t config_size GNUNET_PACKED;
+ uint16_t config_size GNUNET_PACKED;
/* followed by serialized peer configuration;
* gzip'ed configuration file in INI format */
@@ -252,7 +252,7 @@ struct GNUNET_TESTBED_PeerReconfigureMessage
{
/**
- * Type is GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER
+ * Type is GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER
*/
struct GNUNET_MessageHeader header;
@@ -266,6 +266,11 @@ struct GNUNET_TESTBED_PeerReconfigureMessage
*/
uint64_t operation_id GNUNET_PACKED;
+ /**
+ * The length of the serialized configuration when uncompressed
+ */
+ uint16_t config_size GNUNET_PACKED;
+
/* followed by serialized peer configuration;
* gzip'ed configuration file in INI format */
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 207f2658f7..01df06729a 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -455,6 +455,8 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
opc->data = NULL;
}
break;
+ case OP_PEER_RECONFIGURE:
+ break;
default:
GNUNET_assert (0);
}
@@ -780,6 +782,7 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
struct OperationContext *opc;
const char *emsg;
uint64_t op_id;
+ uint64_t mask;
struct GNUNET_TESTBED_EventInformation event;
op_id = GNUNET_ntohll (msg->operation_id);
@@ -814,8 +817,8 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
event.op_cls = opc->op_cls;
event.details.operation_finished.emsg = emsg;
event.details.operation_finished.generic = NULL;
- if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
- (NULL != c->cc))
+ mask = (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
+ if ((0 != (mask & c->event_mask)) && (NULL != c->cc))
{
exop_insert (event.op);
c->cc (c->cc_cls, &event);
@@ -1939,6 +1942,28 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg)
xdata = (const Bytef *) &imsg[1];
}
break;
+ case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER:
+ {
+ const struct GNUNET_TESTBED_PeerCreateMessage *imsg;
+
+ imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *) msg;
+ data_len = ntohs (imsg->config_size);
+ xdata_len = ntohs (imsg->header.size) -
+ sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
+ xdata = (const Bytef *) &imsg[1];
+ }
+ break;
+ case GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER:
+ {
+ const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg;
+
+ imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) msg;
+ data_len = ntohs (imsg->config_size);
+ xdata_len = ntohs (imsg->header.size) -
+ sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage);
+ xdata = (const Bytef *) &imsg[1];
+ }
+ break;
default:
GNUNET_assert (0);
}
@@ -1946,7 +1971,7 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg)
if (Z_OK != (ret = uncompress (data, &data_len, xdata, xdata_len)))
{
GNUNET_free (data);
- GNUNET_break_op (0);
+ GNUNET_break_op (0); /* Un-compression failure */
return NULL;
}
cfg = GNUNET_CONFIGURATION_create ();
@@ -1956,7 +1981,7 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg)
GNUNET_NO))
{
GNUNET_free (data);
- GNUNET_break_op (0);
+ GNUNET_break_op (0); /* De-serialization failure */
return NULL;
}
GNUNET_free (data);
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index 320289bb09..dbeea92437 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -67,6 +67,11 @@ enum OperationType
*/
OP_PEER_INFO,
+ /**
+ * Reconfigure a peer
+ */
+ OP_PEER_RECONFIGURE,
+
/**
* Overlay connection operation
*/
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 8341a96a3b..e9328ffb83 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -120,7 +120,7 @@ opstart_peer_create (void *cls)
msg->operation_id = GNUNET_htonll (opc->id);
msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host));
msg->peer_id = htonl (data->peer->unique_id);
- msg->config_size = htonl (c_size);
+ msg->config_size = htons ((uint16_t) c_size);
GNUNET_TESTBED_insert_opc_ (opc->c, opc);
GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
}
@@ -457,6 +457,71 @@ oprelease_overlay_connect (void *cls)
/**
+ * Function called when a peer reconfigure operation is ready
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+opstart_peer_reconfigure (void *cls)
+{
+ struct OperationContext *opc = cls;
+ struct PeerReconfigureData *data = opc->data;
+ struct GNUNET_TESTBED_PeerReconfigureMessage *msg;
+ char *xconfig;
+ size_t xc_size;
+ uint16_t msize;
+
+ opc->state = OPC_STATE_STARTED;
+ GNUNET_assert (NULL != data);
+ xc_size = GNUNET_TESTBED_compress_config_ (data->config, data->cfg_size,
+ &xconfig);
+ GNUNET_free (data->config);
+ data->config = NULL;
+ GNUNET_assert (xc_size <= UINT16_MAX);
+ msize = (uint16_t) xc_size +
+ sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage);
+ msg = GNUNET_realloc (xconfig, msize);
+ (void) memmove (&msg[1], msg, xc_size);
+ msg->header.size = htons (msize);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER);
+ msg->peer_id = htonl (data->peer->unique_id);
+ msg->operation_id = GNUNET_htonll (opc->id);
+ msg->config_size = htons (data->cfg_size);
+ GNUNET_free (data);
+ opc->data = NULL;
+ GNUNET_TESTBED_insert_opc_ (opc->c, opc);
+ GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
+}
+
+
+/**
+ * Callback which will be called when a peer reconfigure operation is released
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+oprelease_peer_reconfigure (void *cls)
+{
+ struct OperationContext *opc = cls;
+ struct PeerReconfigureData *data = opc->data;
+
+ switch (opc->state)
+ {
+ case OPC_STATE_INIT:
+ GNUNET_free (data->config);
+ GNUNET_free (data);
+ break;
+ case OPC_STATE_STARTED:
+ GNUNET_TESTBED_remove_opc_ (opc->c, opc);
+ break;
+ case OPC_STATE_FINISHED:
+ break;
+ }
+ GNUNET_free (opc);
+}
+
+
+/**
* Lookup a peer by ID.
*
* @param id global peer ID assigned to the peer
@@ -673,9 +738,38 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
const struct
GNUNET_CONFIGURATION_Handle *cfg)
{
- // FIXME: handle locally or delegate...
- GNUNET_break (0);
- return NULL;
+ struct OperationContext *opc;
+ struct PeerReconfigureData *data;
+ size_t csize;
+
+ data = GNUNET_malloc (sizeof (struct PeerReconfigureData));
+ data->peer = peer;
+ data->config = GNUNET_CONFIGURATION_serialize (cfg, &csize);
+ if (NULL == data->config)
+ {
+ GNUNET_free (data);
+ return NULL;
+ }
+ if (csize > UINT16_MAX)
+ {
+ GNUNET_break (0);
+ GNUNET_free (data->config);
+ GNUNET_free (data);
+ return NULL;
+ }
+ data->cfg_size = (uint16_t) csize;
+ opc = GNUNET_malloc (sizeof (struct OperationContext));
+ opc->c = peer->controller;
+ opc->data = data;
+ opc->type = OP_PEER_RECONFIGURE;
+ opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
+ opc->op =
+ GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_reconfigure,
+ &oprelease_peer_reconfigure);
+ GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
+ opc->op);
+ GNUNET_TESTBED_operation_begin_wait_ (opc->op);
+ return opc->op;
}
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index 10deed67d3..50fb29bf6a 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -196,6 +196,28 @@ struct PeerInfoData
/**
+ * Data for the operations of type OP_PEER_RECONFIGURE
+ */
+struct PeerReconfigureData
+{
+ /**
+ * The peer whose information has been requested
+ */
+ struct GNUNET_TESTBED_Peer *peer;
+
+ /**
+ * The serialized new configuration template
+ */
+ char *config;
+
+ /**
+ * the size of the serialized configuration
+ */
+ uint16_t cfg_size;
+};
+
+
+/**
* Data structure for OperationType OP_OVERLAY_CONNECT
*/
struct OverlayConnectData