From 71f190d1d34a96f7126e07128a975b798474f114 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Sun, 8 Jul 2012 22:25:06 +0000 Subject: [PATCH] -client handle operation success --- src/testbed/gnunet-service-testbed.c | 2 + src/testbed/testbed_api.c | 83 +++++++++++++++++++++++++++- src/testbed/testbed_api_peers.c | 54 ------------------ src/testbed/testbed_api_peers.h | 53 ++++++++++++++++++ 4 files changed, 137 insertions(+), 55 deletions(-) diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index b947ee7d6..e05e1d71f 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -1176,6 +1176,8 @@ handle_peer_destroy (void *cls, msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message; 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 ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id])) { GNUNET_break (0); diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index b290e748c..2eada0974 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -39,6 +39,7 @@ #include "testbed.h" #include "testbed_api.h" #include "testbed_api_hosts.h" +#include "testbed_api_peers.h" /** * Generic logging shorthand @@ -321,6 +322,81 @@ handle_addhostconfirm (struct GNUNET_TESTBED_Controller *c, } +/** + * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from + * controller (testbed service) + * + * @param c the controller handler + * @param msg message received + * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if + * not + */ +static int +handle_opsuccess (struct GNUNET_TESTBED_Controller *c, + const struct + GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg) +{ + struct GNUNET_TESTBED_Operation *op; + struct GNUNET_TESTBED_EventInformation *event; + uint64_t op_id; + + op_id = GNUNET_ntohll (msg->operation_id); + LOG_DEBUG ("Operation %ul successful\n", op_id); + for (op = op_head; NULL != op; op = op->next) + { + if (op->operation_id == op_id) + break; + } + if (NULL == op) + { + LOG_DEBUG ("Operation not found\n"); + return GNUNET_YES; + } + event = NULL; + if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) + event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation)); + if (NULL != event) + event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; + switch (op->type) + { + case OP_PEER_DESTROY: + { + struct PeerDestroyData *data; + + if (NULL != event) + { + event->details.operation_finished.operation = op; + event->details.operation_finished.op_cls = NULL; + event->details.operation_finished.emsg = NULL; + event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; + event->details.operation_finished.op_result.generic = NULL; + } + data = (struct PeerDestroyData *) op->data; + if (NULL != data->peer->details) + { + if (NULL != data->peer->details->cfg) + GNUNET_CONFIGURATION_destroy (data->peer->details->cfg); + //PEER_DETAILS + } + GNUNET_free (data->peer); + GNUNET_free (data); + //PEERDESTROYDATA + } + break; + default: + GNUNET_break (0); + } + if (NULL != event) + { + if (NULL != c->cc) + c->cc (c->cc_cls, event); + } + GNUNET_CONTAINER_DLL_remove (op_head, op_tail, op); + GNUNET_free (op); + return GNUNET_YES; +} + + /** * Handler for messages from controller (testbed service) * @@ -346,8 +422,13 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) case GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM: status = handle_addhostconfirm (c, (const struct - GNUNET_TESTBED_HostConfirmedMessage *) msg); + GNUNET_TESTBED_HostConfirmedMessage *) msg); break; + case GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS: + status = + handle_opsuccess (c, (const struct + GNUNET_TESTBED_GenericOperationSuccessEventMessage + *) msg); default: GNUNET_break (0); } diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 2fe8ce26d..3cd89f2f6 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c @@ -30,60 +30,6 @@ #include "testbed.h" #include "testbed_api_hosts.h" -/** - * Details about a peer; kept in a separate struct to avoid bloating - * memory consumption everywhere... - */ -struct PeerDetails -{ - /** - * Configuration of the peer; NULL if we are not sure what the peer's correct - * configuration actually is; non-NULL if this peer is controlled by this - * process. - */ - struct GNUNET_CONFIGURATION_Handle *cfg; - - /** - * If this process has started this peer's ARM process, this is the handle - * to the 'gnunet-service-arm' process of the peer. - */ - struct GNUNET_OS_Process *arm; - - // ... - -}; - - -/** - * A peer controlled by the testing framework. A peer runs - * at a particular host. - */ -struct GNUNET_TESTBED_Peer -{ - /** - * Our controller context (not necessarily the controller - * that is responsible for starting/running the peer!). - */ - struct GNUNET_TESTBED_Controller *controller; - - /** - * Which host does this peer run on? - */ - struct GNUNET_TESTBED_Host *host; - - /** - * Globally unique ID of the peer. - */ - uint32_t unique_id; - - /** - * Internals of the peer for the controlling process; NULL if - * this process is not controlling this peer. - */ - struct PeerDetails *details; - -}; - /** * Lookup a peer by ID. diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index 3a9244fc2..ee5ec3bd9 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h @@ -30,12 +30,65 @@ #include "gnunet_helper_lib.h" +/** + * Details about a peer; kept in a separate struct to avoid bloating + * memory consumption everywhere... + */ +struct PeerDetails +{ + /** + * Configuration of the peer; NULL if we are not sure what the peer's correct + * configuration actually is; non-NULL if this peer is controlled by this + * process. + */ + struct GNUNET_CONFIGURATION_Handle *cfg; + + //PEER_DETAILS +}; + + +/** + * A peer controlled by the testing framework. A peer runs + * at a particular host. + */ +struct GNUNET_TESTBED_Peer +{ + /** + * Our controller context (not necessarily the controller + * that is responsible for starting/running the peer!). + */ + struct GNUNET_TESTBED_Controller *controller; + + /** + * Which host does this peer run on? + */ + struct GNUNET_TESTBED_Host *host; + + /** + * Globally unique ID of the peer. + */ + uint32_t unique_id; + + /** + * Internals of the peer for the controlling process; NULL if + * this process is not controlling this peer. + */ + struct PeerDetails *details; + +}; + + /** * Data for the OperationType OP_PEER_DESTROY; */ struct PeerDestroyData { + /** + * The peer structure + */ struct GNUNET_TESTBED_Peer *peer; + + //PEERDESTROYDATA }; -- 2.25.1