[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23018 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23018 - gnunet/src/testbed |
Date: |
Tue, 31 Jul 2012 16:52:41 +0200 |
Author: harsha
Date: 2012-07-31 16:52:41 +0200 (Tue, 31 Jul 2012)
New Revision: 23018
Modified:
gnunet/src/testbed/testbed.conf.in
gnunet/src/testbed/testbed_api.c
gnunet/src/testbed/testbed_api.h
gnunet/src/testbed/testbed_api_operations.c
gnunet/src/testbed/testbed_api_peers.c
gnunet/src/testbed/testbed_api_peers.h
Log:
peer create with new operations handling
Modified: gnunet/src/testbed/testbed.conf.in
===================================================================
--- gnunet/src/testbed/testbed.conf.in 2012-07-31 14:52:20 UTC (rev 23017)
+++ gnunet/src/testbed/testbed.conf.in 2012-07-31 14:52:41 UTC (rev 23018)
@@ -10,3 +10,4 @@
UNIXPATH = /tmp/gnunet-service-testbed.sock
UNIX_MATCH_UID = YES
UNIX_MATCH_GID = YES
+MAX_PARALLEL_PEER_CREATE = 1000
\ No newline at end of file
Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c 2012-07-31 14:52:20 UTC (rev 23017)
+++ gnunet/src/testbed/testbed_api.c 2012-07-31 14:52:41 UTC (rev 23018)
@@ -40,6 +40,7 @@
#include "testbed_api.h"
#include "testbed_api_hosts.h"
#include "testbed_api_peers.h"
+#include "testbed_api_operations.h"
/**
* Generic logging shorthand
@@ -299,7 +300,7 @@
const struct
GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg)
{
- struct GNUNET_TESTBED_Operation *op;
+ struct OperationContext *opc;
struct PeerCreateData *data;
struct GNUNET_TESTBED_Peer *peer;
GNUNET_TESTBED_PeerCreateCallback cb;
@@ -309,28 +310,25 @@
GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)
== ntohs (msg->header.size));
op_id = GNUNET_ntohll (msg->operation_id);
- for (op = c->op_head; NULL != op; op = op->next)
+ for (opc = c->ocq_head; NULL != opc; opc = opc->next)
{
- if (op->operation_id == op_id)
+ if (opc->id == op_id)
break;
}
- if (NULL == op)
+ if (NULL == opc)
{
- LOG_DEBUG ("Operation not found\n");
+ LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n");
return GNUNET_YES;
}
- GNUNET_assert (OP_PEER_CREATE == op->type);
- GNUNET_assert (NULL != op->data);
- data = op->data;
+ GNUNET_assert (OP_PEER_CREATE == opc->type);
+ GNUNET_assert (NULL != opc->data);
+ data = opc->data;
GNUNET_assert (NULL != data->peer);
peer = data->peer;
GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
peer->state = PS_CREATED;
cb = data->cb;
- cls = data->cls;
- GNUNET_free (data);
- op->data = NULL;
- GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
+ cls = data->cls;
if (NULL != cb)
cb (cls, peer, NULL);
return GNUNET_YES;
@@ -936,7 +934,16 @@
{
struct GNUNET_TESTBED_Controller *controller;
struct GNUNET_TESTBED_InitMessage *msg;
+ unsigned long long max_parallel_peer_create;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg, "testbed",
+ "MAX_PARALLEL_PEER_CREATE",
+ &max_parallel_peer_create))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller));
controller->cc = cc;
controller->cc_cls = cc_cls;
@@ -954,8 +961,8 @@
if (NULL == host)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Treating NULL host as localhost. Multiple references to localhost. "
- " May break when localhost freed before calling disconnect \n");
+ "Treating NULL host as localhost. Multiple references to localhost "
+ "may break when localhost freed before calling disconnect \n");
host = GNUNET_TESTBED_host_lookup_by_id_ (0);
}
else
@@ -964,12 +971,17 @@
}
}
GNUNET_assert (NULL != host);
+ controller->opq_peer_create =
+ GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
+ max_parallel_peer_create);
msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage));
msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage));
msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
msg->event_mask = GNUNET_htonll (controller->event_mask);
- GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *)
msg);
+ GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *)
+ msg);
+
return controller;
}
@@ -1035,6 +1047,7 @@
GNUNET_CONFIGURATION_destroy (controller->cfg);
if (GNUNET_YES == controller->aux_host)
GNUNET_TESTBED_host_destroy (controller->host);
+ GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_peer_create);
GNUNET_free (controller);
}
@@ -1338,8 +1351,8 @@
switch (operation->type)
{
case OP_PEER_CREATE:
- GNUNET_free_non_null (operation->data);
- break;
+ GNUNET_TESTBED_operation_release_ (operation);
+ return;
case OP_PEER_DESTROY:
GNUNET_free_non_null (operation->data);
break;
Modified: gnunet/src/testbed/testbed_api.h
===================================================================
--- gnunet/src/testbed/testbed_api.h 2012-07-31 14:52:20 UTC (rev 23017)
+++ gnunet/src/testbed/testbed_api.h 2012-07-31 14:52:41 UTC (rev 23018)
@@ -108,13 +108,54 @@
*/
struct MessageQueue;
-
/**
* Structure for a controller link
*/
struct ControllerLink;
+/**
+ * Context information for GNUNET_TESTBED_Operation
+ */
+struct OperationContext
+{
+ /**
+ * next ptr for DLL
+ */
+ struct OperationContext *next;
+ /**
+ * prev ptr for DLL
+ */
+ struct OperationContext *prev;
+
+ /**
+ * The controller to which this operation context belongs to
+ */
+ struct GNUNET_TESTBED_Controller *c;
+
+ /**
+ * The operation
+ */
+ struct GNUNET_TESTBED_Operation *op;
+
+ /**
+ * Data relevant to the operation
+ */
+ void *data;
+
+ /**
+ * The id of the opearation
+ */
+ uint64_t id;
+
+ /**
+ * The type of operation
+ */
+ enum OperationType type;
+
+};
+
+
/**
* Handle to interact with a GNUnet testbed controller. Each
* controller has at least one master handle which is created when the
@@ -184,16 +225,31 @@
struct GNUNET_TESTBED_HostRegistrationHandle *rh;
/**
- * The head of the operation queue
+ * The head of the operation queue (FIXME: Remove, use ocq)
*/
struct GNUNET_TESTBED_Operation *op_head;
/**
- * The tail of the operation queue
+ * The tail of the operation queue (FIXME: Remove, use ocq)
*/
struct GNUNET_TESTBED_Operation *op_tail;
/**
+ * The head of the opeartion context queue
+ */
+ struct OperationContext *ocq_head;
+
+ /**
+ * The tail of the operation context queue
+ */
+ struct OperationContext *ocq_tail;
+
+ /**
+ * Operation queue for simultaneous peer creations
+ */
+ struct OperationQueue *opq_peer_create;
+
+ /**
* The operation id counter. use current value and increment
*/
uint64_t operation_counter;
Modified: gnunet/src/testbed/testbed_api_operations.c
===================================================================
--- gnunet/src/testbed/testbed_api_operations.c 2012-07-31 14:52:20 UTC (rev
23017)
+++ gnunet/src/testbed/testbed_api_operations.c 2012-07-31 14:52:41 UTC (rev
23018)
@@ -227,8 +227,8 @@
void
GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
{
- GNUNET_assert (NULL == queue->head);
- GNUNET_assert (NULL == queue->tail);
+ GNUNET_break (NULL == queue->head);
+ GNUNET_break (NULL == queue->tail);
GNUNET_free (queue);
}
Modified: gnunet/src/testbed/testbed_api_peers.c
===================================================================
--- gnunet/src/testbed/testbed_api_peers.c 2012-07-31 14:52:20 UTC (rev
23017)
+++ gnunet/src/testbed/testbed_api_peers.c 2012-07-31 14:52:41 UTC (rev
23018)
@@ -29,9 +29,68 @@
#include "testbed_api.h"
#include "testbed.h"
#include "testbed_api_hosts.h"
+#include "testbed_api_operations.h"
+/**
+ * Function to call to start a peer_create type operation once all
+ * queues the operation is part of declare that the
+ * operation can be activated.
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+opstart_peer_create (void *cls)
+{
+ struct OperationContext *opc = cls;
+ struct PeerCreateData *data;
+ struct GNUNET_TESTBED_PeerCreateMessage *msg;
+ char *config;
+ char *xconfig;
+ size_t c_size;
+ size_t xc_size;
+ uint16_t msize;
+ GNUNET_assert (OP_PEER_CREATE == opc->type);
+ data = opc->data;
+ GNUNET_assert (NULL != data);
+ GNUNET_assert (NULL != data->peer);
+ config = GNUNET_CONFIGURATION_serialize (data->cfg, &c_size);
+ xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
+ GNUNET_free (config);
+ msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
+ msg = GNUNET_realloc (xconfig, msize);
+ memmove (&msg[1], msg, xc_size);
+ msg->header.size = htons (msize);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
+ 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);
+ GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head,
+ opc->c->ocq_tail, opc);
+ GNUNET_TESTBED_queue_message_ (opc->c,
+ (struct GNUNET_MessageHeader *) msg);
+};
+
+
/**
+ * Callback which will be called when peer_create type operation is released
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+oprelease_peer_create (void *cls)
+{
+ struct OperationContext *opc = cls;
+
+ GNUNET_assert (NULL != opc->data);
+ GNUNET_free (opc->data);
+ GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+ GNUNET_free (opc);
+}
+
+
+/**
* Lookup a peer by ID.
*
* @param id global peer ID assigned to the peer
@@ -71,7 +130,8 @@
* @param unique_id unique ID for this peer
* @param controller controller process to use
* @param host host to run the peer on
- * @param cfg configuration to use for the peer
+ * @param cfg Template configuration to use for the peer. Should exist until
+ * operation is cancelled or GNUNET_TESTBED_operation_done() is called
* @param cb the callback to call when the peer has been created
* @param cls the closure to the above callback
* @return the operation handle
@@ -86,13 +146,7 @@
{
struct GNUNET_TESTBED_Peer *peer;
struct PeerCreateData *data;
- struct GNUNET_TESTBED_Operation *op;
- struct GNUNET_TESTBED_PeerCreateMessage *msg;
- char *config;
- char *xconfig;
- size_t c_size;
- size_t xc_size;
- uint16_t msize;
+ struct OperationContext *opc;
peer = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer));
peer->controller = controller;
@@ -100,31 +154,20 @@
peer->unique_id = unique_id;
peer->state = PS_INVALID;
data = GNUNET_malloc (sizeof (struct PeerCreateData));
+ data->host = host;
+ data->cfg = cfg;
data->cb = cb;
data->cls = cls;
data->peer = peer;
- op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
- op->controller = controller;
- op->operation_id = controller->operation_counter++;
- op->type = OP_PEER_CREATE;
- op->data = data;
- config = GNUNET_CONFIGURATION_serialize (cfg, &c_size);
- xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
- GNUNET_free (config);
- msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
- msg = GNUNET_realloc (xconfig, msize);
- memmove (&msg[1], msg, xc_size); /* Move the compressed config */
- msg->header.size = htons (msize);
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
- msg->operation_id = GNUNET_htonll (op->operation_id);
- msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host));
- msg->peer_id = htonl (peer->unique_id);
- msg->config_size = htonl (c_size);
- GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
- peer->controller->op_tail, op);
- GNUNET_TESTBED_queue_message_ (controller,
- (struct GNUNET_MessageHeader *) msg);
- return op;
+ opc = GNUNET_malloc (sizeof (struct OperationContext));
+ opc->c = controller;
+ opc->data = data;
+ opc->id = controller->operation_counter++;
+ opc->type = OP_PEER_CREATE;
+ opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create,
+ &oprelease_peer_create);
+ GNUNET_TESTBED_operation_queue_insert_ (controller->opq_peer_create,
opc->op);
+ return opc->op;
}
@@ -151,7 +194,8 @@
*
* @param controller controller process to use
* @param host host to run the peer on
- * @param cfg configuration to use for the peer
+ * @param cfg Template configuration to use for the peer. Should exist until
+ * operation is cancelled or GNUNET_TESTBED_operation_done() is called
* @param cb the callback to call when the peer has been created
* @param cls the closure to the above callback
* @return the operation handle
Modified: gnunet/src/testbed/testbed_api_peers.h
===================================================================
--- gnunet/src/testbed/testbed_api_peers.h 2012-07-31 14:52:20 UTC (rev
23017)
+++ gnunet/src/testbed/testbed_api_peers.h 2012-07-31 14:52:41 UTC (rev
23018)
@@ -115,8 +115,18 @@
struct PeerCreateData
{
/**
- * THe call back to call when we receive peer create success message
+ * The host where the peer has to be created
*/
+ struct GNUNET_TESTBED_Host *host;
+
+ /**
+ * The template configuration of the peer
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * The call back to call when we receive peer create success message
+ */
GNUNET_TESTBED_PeerCreateCallback cb;
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23018 - gnunet/src/testbed,
gnunet <=