/**
- * Context data to be used when forwarding peer create messages
+ * Context information for operations forward to subcontrollers
*/
-struct PeerCreateContext
+struct ForwardedOperationContext
{
/**
- * The operation handle to peer create
+ * Task ID for the timeout task
*/
- struct GNUNET_TESTBED_operation *operation;
+ GNUNET_SCHEDULER_TaskIdentifier timeout_task;
/**
- * The ID of the operation which created this context
+ * The ID of the operation that is forwarded
*/
uint64_t operation_id;
-
- /**
- * The peer create timeout task id
- */
- GNUNET_SCHEDULER_TaskIdentifier timeout_task;
-
};
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_TESTBED_PeerCreateMessage *msg;
+ struct GNUNET_TESTBED_PeerCreateMessage *dup_msg;
struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
struct GNUNET_CONFIGURATION_Handle *cfg;
- struct PeerCreateContext *pc_ctxt;
+ struct ForwardedOperationContext *fo_ctxt;
struct Route *route;
+ struct Peer *peer;
char *config;
size_t dest_size;
int ret;
host_id = ntohl (msg->host_id);
if (host_id == master_context->host_id)
{
- struct Peer *peer;
char *emsg;
/* We are responsible for this peer */
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
- pc_ctxt = GNUNET_malloc (sizeof (struct PeerCreateContext));
- pc_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
- /* To be continued .. :) */
+ fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
+ fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
+ dup_msg = GNUNET_malloc (msize);
+ (void) memcpy (dup_msg, msg, msize);
+ GNUNET_TESTBED_queue_message_ (slave_list[route->dest]->controller,
+ &dup_msg->header);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
};
+/**
+ * Context data for forwarded Operation
+ */
+struct ForwardedOperationData
+{
+
+ /**
+ * The callback to call when reply is available
+ */
+ GNUNET_CLIENT_MessageHandler cc;
+
+ /**
+ * The closure for the above callback
+ */
+ void *cc_cls;
+
+};
+
+
/**
* Returns the operation context with the given id if found in the Operation
* context queues of the controller
LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n");
return GNUNET_YES;
}
+ if (OP_FORWARDED == opc->type)
+ {
+ struct ForwardedOperationData *fo_data;
+
+ fo_data = opc->data;
+ if (NULL != fo_data->cc)
+ fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
+ GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
+ GNUNET_free (fo_data);
+ GNUNET_free (opc);
+ return GNUNET_YES;
+ }
GNUNET_assert (OP_PEER_CREATE == opc->type);
GNUNET_assert (NULL != opc->data);
data = opc->data;
}
+/**
+ * Sends the given message as an operation. The given callback is called when a
+ * reply for the operation is available
+ *
+ * @param controller the controller to which the message has to be sent
+ * @param operation_id the operation id of the message
+ * @param msg the message to send
+ * @param cc the callback to call when reply is available
+ * @param cc_cls the closure for the above callback
+ * @return the operation context which can be used to cancel the forwarded
+ * operation
+ */
+struct OperationContext *
+GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
+ * controller,
+ uint64_t operation_id,
+ const struct GNUNET_MessageHeader *msg,
+ GNUNET_CLIENT_MessageHandler cc,
+ void *cc_cls)
+{
+ struct OperationContext *opc;
+ struct ForwardedOperationData *data;
+ struct GNUNET_MessageHeader *dup_msg;
+ uint16_t msize;
+
+ data = GNUNET_malloc (sizeof (struct ForwardedOperationData));
+ data->cc = cc;
+ data->cc_cls = cc_cls;
+ opc = GNUNET_malloc (sizeof (struct OperationContext));
+ opc->type = OP_FORWARDED;
+ opc->data = data;
+ opc->id = operation_id;
+ msize = ntohs (msg->size);
+ dup_msg = GNUNET_malloc (msize);
+ (void) memcpy (dup_msg, msg, msize);
+ GNUNET_TESTBED_queue_message_ (opc->c, dup_msg);
+ GNUNET_CONTAINER_DLL_insert_tail (controller->ocq_head,
+ controller->ocq_tail, opc);
+ return opc;
+}
+
+
/**
* Handle for controller process
*/
}
}
-
/* end of testbed_api.c */
*/
OP_OVERLAY_CONNECT,
+ /**
+ * Forwarded operation
+ */
+ OP_FORWARDED
+
};
GNUNET_CONFIGURATION_Handle *cfg);
+/**
+ * Sends the given message as an operation. The given callback is called when a
+ * reply for the operation is available
+ *
+ * @param controller the controller to which the message has to be sent
+ * @param operation_id the operation id of the message
+ * @param msg the message to send
+ * @param cc the callback to call when reply is available
+ * @param cc_cls the closure for the above callback
+ * @return the operation context which can be used to cancel the forwarded
+ * operation
+ */
+struct OperationContext *
+GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
+ * controller,
+ uint64_t operation_id,
+ const struct GNUNET_MessageHeader *msg,
+ GNUNET_CLIENT_MessageHandler cc,
+ void *cc_cls);
+
#endif
+/* end of testbed_api.h */