aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-31 14:52:41 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-31 14:52:41 +0000
commitf941bca886b577fd14235686c3100accc2beb03c (patch)
tree7e6d2916ee51deeb14106f56df1d22d4f91efe50 /src/testbed
parent7e2e6f55d1bf7ab87c9df180bfa6841480f99ab8 (diff)
downloadgnunet-f941bca886b577fd14235686c3100accc2beb03c.tar.gz
gnunet-f941bca886b577fd14235686c3100accc2beb03c.zip
peer create with new operations handling
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/testbed.conf.in1
-rw-r--r--src/testbed/testbed_api.c47
-rw-r--r--src/testbed/testbed_api.h62
-rw-r--r--src/testbed/testbed_api_operations.c4
-rw-r--r--src/testbed/testbed_api_peers.c106
-rw-r--r--src/testbed/testbed_api_peers.h12
6 files changed, 178 insertions, 54 deletions
diff --git a/src/testbed/testbed.conf.in b/src/testbed/testbed.conf.in
index 2f658fddd..bed5e7f78 100644
--- a/src/testbed/testbed.conf.in
+++ b/src/testbed/testbed.conf.in
@@ -10,3 +10,4 @@ ACCEPT_FROM6 = ::1;
10UNIXPATH = /tmp/gnunet-service-testbed.sock 10UNIXPATH = /tmp/gnunet-service-testbed.sock
11UNIX_MATCH_UID = YES 11UNIX_MATCH_UID = YES
12UNIX_MATCH_GID = YES 12UNIX_MATCH_GID = YES
13MAX_PARALLEL_PEER_CREATE = 1000 \ No newline at end of file
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 365a8cdee..de64b3b49 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -40,6 +40,7 @@
40#include "testbed_api.h" 40#include "testbed_api.h"
41#include "testbed_api_hosts.h" 41#include "testbed_api_hosts.h"
42#include "testbed_api_peers.h" 42#include "testbed_api_peers.h"
43#include "testbed_api_operations.h"
43 44
44/** 45/**
45 * Generic logging shorthand 46 * Generic logging shorthand
@@ -299,7 +300,7 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
299 const struct 300 const struct
300 GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg) 301 GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg)
301{ 302{
302 struct GNUNET_TESTBED_Operation *op; 303 struct OperationContext *opc;
303 struct PeerCreateData *data; 304 struct PeerCreateData *data;
304 struct GNUNET_TESTBED_Peer *peer; 305 struct GNUNET_TESTBED_Peer *peer;
305 GNUNET_TESTBED_PeerCreateCallback cb; 306 GNUNET_TESTBED_PeerCreateCallback cb;
@@ -309,28 +310,25 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
309 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) 310 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)
310 == ntohs (msg->header.size)); 311 == ntohs (msg->header.size));
311 op_id = GNUNET_ntohll (msg->operation_id); 312 op_id = GNUNET_ntohll (msg->operation_id);
312 for (op = c->op_head; NULL != op; op = op->next) 313 for (opc = c->ocq_head; NULL != opc; opc = opc->next)
313 { 314 {
314 if (op->operation_id == op_id) 315 if (opc->id == op_id)
315 break; 316 break;
316 } 317 }
317 if (NULL == op) 318 if (NULL == opc)
318 { 319 {
319 LOG_DEBUG ("Operation not found\n"); 320 LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n");
320 return GNUNET_YES; 321 return GNUNET_YES;
321 } 322 }
322 GNUNET_assert (OP_PEER_CREATE == op->type); 323 GNUNET_assert (OP_PEER_CREATE == opc->type);
323 GNUNET_assert (NULL != op->data); 324 GNUNET_assert (NULL != opc->data);
324 data = op->data; 325 data = opc->data;
325 GNUNET_assert (NULL != data->peer); 326 GNUNET_assert (NULL != data->peer);
326 peer = data->peer; 327 peer = data->peer;
327 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id)); 328 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
328 peer->state = PS_CREATED; 329 peer->state = PS_CREATED;
329 cb = data->cb; 330 cb = data->cb;
330 cls = data->cls; 331 cls = data->cls;
331 GNUNET_free (data);
332 op->data = NULL;
333 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
334 if (NULL != cb) 332 if (NULL != cb)
335 cb (cls, peer, NULL); 333 cb (cls, peer, NULL);
336 return GNUNET_YES; 334 return GNUNET_YES;
@@ -936,7 +934,16 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
936{ 934{
937 struct GNUNET_TESTBED_Controller *controller; 935 struct GNUNET_TESTBED_Controller *controller;
938 struct GNUNET_TESTBED_InitMessage *msg; 936 struct GNUNET_TESTBED_InitMessage *msg;
937 unsigned long long max_parallel_peer_create;
939 938
939 if (GNUNET_OK !=
940 GNUNET_CONFIGURATION_get_value_number (cfg, "testbed",
941 "MAX_PARALLEL_PEER_CREATE",
942 &max_parallel_peer_create))
943 {
944 GNUNET_break (0);
945 return NULL;
946 }
940 controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller)); 947 controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller));
941 controller->cc = cc; 948 controller->cc = cc;
942 controller->cc_cls = cc_cls; 949 controller->cc_cls = cc_cls;
@@ -954,8 +961,8 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
954 if (NULL == host) 961 if (NULL == host)
955 { 962 {
956 LOG (GNUNET_ERROR_TYPE_WARNING, 963 LOG (GNUNET_ERROR_TYPE_WARNING,
957 "Treating NULL host as localhost. Multiple references to localhost. " 964 "Treating NULL host as localhost. Multiple references to localhost "
958 " May break when localhost freed before calling disconnect \n"); 965 "may break when localhost freed before calling disconnect \n");
959 host = GNUNET_TESTBED_host_lookup_by_id_ (0); 966 host = GNUNET_TESTBED_host_lookup_by_id_ (0);
960 } 967 }
961 else 968 else
@@ -964,12 +971,17 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
964 } 971 }
965 } 972 }
966 GNUNET_assert (NULL != host); 973 GNUNET_assert (NULL != host);
974 controller->opq_peer_create =
975 GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
976 max_parallel_peer_create);
967 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage)); 977 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage));
968 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); 978 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
969 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage)); 979 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage));
970 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); 980 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
971 msg->event_mask = GNUNET_htonll (controller->event_mask); 981 msg->event_mask = GNUNET_htonll (controller->event_mask);
972 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) msg); 982 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *)
983 msg);
984
973 return controller; 985 return controller;
974} 986}
975 987
@@ -1035,6 +1047,7 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controll
1035 GNUNET_CONFIGURATION_destroy (controller->cfg); 1047 GNUNET_CONFIGURATION_destroy (controller->cfg);
1036 if (GNUNET_YES == controller->aux_host) 1048 if (GNUNET_YES == controller->aux_host)
1037 GNUNET_TESTBED_host_destroy (controller->host); 1049 GNUNET_TESTBED_host_destroy (controller->host);
1050 GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_peer_create);
1038 GNUNET_free (controller); 1051 GNUNET_free (controller);
1039} 1052}
1040 1053
@@ -1338,8 +1351,8 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation)
1338 switch (operation->type) 1351 switch (operation->type)
1339 { 1352 {
1340 case OP_PEER_CREATE: 1353 case OP_PEER_CREATE:
1341 GNUNET_free_non_null (operation->data); 1354 GNUNET_TESTBED_operation_release_ (operation);
1342 break; 1355 return;
1343 case OP_PEER_DESTROY: 1356 case OP_PEER_DESTROY:
1344 GNUNET_free_non_null (operation->data); 1357 GNUNET_free_non_null (operation->data);
1345 break; 1358 break;
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index 642fc4ccb..9d0d8076d 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -108,12 +108,53 @@ struct GNUNET_TESTBED_Operation
108 */ 108 */
109struct MessageQueue; 109struct MessageQueue;
110 110
111
112/** 111/**
113 * Structure for a controller link 112 * Structure for a controller link
114 */ 113 */
115struct ControllerLink; 114struct ControllerLink;
116 115
116/**
117 * Context information for GNUNET_TESTBED_Operation
118 */
119struct OperationContext
120{
121 /**
122 * next ptr for DLL
123 */
124 struct OperationContext *next;
125
126 /**
127 * prev ptr for DLL
128 */
129 struct OperationContext *prev;
130
131 /**
132 * The controller to which this operation context belongs to
133 */
134 struct GNUNET_TESTBED_Controller *c;
135
136 /**
137 * The operation
138 */
139 struct GNUNET_TESTBED_Operation *op;
140
141 /**
142 * Data relevant to the operation
143 */
144 void *data;
145
146 /**
147 * The id of the opearation
148 */
149 uint64_t id;
150
151 /**
152 * The type of operation
153 */
154 enum OperationType type;
155
156};
157
117 158
118/** 159/**
119 * Handle to interact with a GNUnet testbed controller. Each 160 * Handle to interact with a GNUnet testbed controller. Each
@@ -184,16 +225,31 @@ struct GNUNET_TESTBED_Controller
184 struct GNUNET_TESTBED_HostRegistrationHandle *rh; 225 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
185 226
186 /** 227 /**
187 * The head of the operation queue 228 * The head of the operation queue (FIXME: Remove, use ocq)
188 */ 229 */
189 struct GNUNET_TESTBED_Operation *op_head; 230 struct GNUNET_TESTBED_Operation *op_head;
190 231
191 /** 232 /**
192 * The tail of the operation queue 233 * The tail of the operation queue (FIXME: Remove, use ocq)
193 */ 234 */
194 struct GNUNET_TESTBED_Operation *op_tail; 235 struct GNUNET_TESTBED_Operation *op_tail;
195 236
196 /** 237 /**
238 * The head of the opeartion context queue
239 */
240 struct OperationContext *ocq_head;
241
242 /**
243 * The tail of the operation context queue
244 */
245 struct OperationContext *ocq_tail;
246
247 /**
248 * Operation queue for simultaneous peer creations
249 */
250 struct OperationQueue *opq_peer_create;
251
252 /**
197 * The operation id counter. use current value and increment 253 * The operation id counter. use current value and increment
198 */ 254 */
199 uint64_t operation_counter; 255 uint64_t operation_counter;
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index 5758e2aa9..6ad15e22e 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -227,8 +227,8 @@ GNUNET_TESTBED_operation_queue_create_ (unsigned int max_active)
227void 227void
228GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) 228GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
229{ 229{
230 GNUNET_assert (NULL == queue->head); 230 GNUNET_break (NULL == queue->head);
231 GNUNET_assert (NULL == queue->tail); 231 GNUNET_break (NULL == queue->tail);
232 GNUNET_free (queue); 232 GNUNET_free (queue);
233} 233}
234 234
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 4571b78df..3ecb38325 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -29,6 +29,65 @@
29#include "testbed_api.h" 29#include "testbed_api.h"
30#include "testbed.h" 30#include "testbed.h"
31#include "testbed_api_hosts.h" 31#include "testbed_api_hosts.h"
32#include "testbed_api_operations.h"
33
34/**
35 * Function to call to start a peer_create type operation once all
36 * queues the operation is part of declare that the
37 * operation can be activated.
38 *
39 * @param cls the closure from GNUNET_TESTBED_operation_create_()
40 */
41static void
42opstart_peer_create (void *cls)
43{
44 struct OperationContext *opc = cls;
45 struct PeerCreateData *data;
46 struct GNUNET_TESTBED_PeerCreateMessage *msg;
47 char *config;
48 char *xconfig;
49 size_t c_size;
50 size_t xc_size;
51 uint16_t msize;
52
53 GNUNET_assert (OP_PEER_CREATE == opc->type);
54 data = opc->data;
55 GNUNET_assert (NULL != data);
56 GNUNET_assert (NULL != data->peer);
57 config = GNUNET_CONFIGURATION_serialize (data->cfg, &c_size);
58 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
59 GNUNET_free (config);
60 msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
61 msg = GNUNET_realloc (xconfig, msize);
62 memmove (&msg[1], msg, xc_size);
63 msg->header.size = htons (msize);
64 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
65 msg->operation_id = GNUNET_htonll (opc->id);
66 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host));
67 msg->peer_id = htonl (data->peer->unique_id);
68 msg->config_size = htonl (c_size);
69 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head,
70 opc->c->ocq_tail, opc);
71 GNUNET_TESTBED_queue_message_ (opc->c,
72 (struct GNUNET_MessageHeader *) msg);
73};
74
75
76/**
77 * Callback which will be called when peer_create type operation is released
78 *
79 * @param cls the closure from GNUNET_TESTBED_operation_create_()
80 */
81static void
82oprelease_peer_create (void *cls)
83{
84 struct OperationContext *opc = cls;
85
86 GNUNET_assert (NULL != opc->data);
87 GNUNET_free (opc->data);
88 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
89 GNUNET_free (opc);
90}
32 91
33 92
34/** 93/**
@@ -71,7 +130,8 @@ GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id)
71 * @param unique_id unique ID for this peer 130 * @param unique_id unique ID for this peer
72 * @param controller controller process to use 131 * @param controller controller process to use
73 * @param host host to run the peer on 132 * @param host host to run the peer on
74 * @param cfg configuration to use for the peer 133 * @param cfg Template configuration to use for the peer. Should exist until
134 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
75 * @param cb the callback to call when the peer has been created 135 * @param cb the callback to call when the peer has been created
76 * @param cls the closure to the above callback 136 * @param cls the closure to the above callback
77 * @return the operation handle 137 * @return the operation handle
@@ -86,13 +146,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
86{ 146{
87 struct GNUNET_TESTBED_Peer *peer; 147 struct GNUNET_TESTBED_Peer *peer;
88 struct PeerCreateData *data; 148 struct PeerCreateData *data;
89 struct GNUNET_TESTBED_Operation *op; 149 struct OperationContext *opc;
90 struct GNUNET_TESTBED_PeerCreateMessage *msg;
91 char *config;
92 char *xconfig;
93 size_t c_size;
94 size_t xc_size;
95 uint16_t msize;
96 150
97 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer)); 151 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer));
98 peer->controller = controller; 152 peer->controller = controller;
@@ -100,31 +154,20 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
100 peer->unique_id = unique_id; 154 peer->unique_id = unique_id;
101 peer->state = PS_INVALID; 155 peer->state = PS_INVALID;
102 data = GNUNET_malloc (sizeof (struct PeerCreateData)); 156 data = GNUNET_malloc (sizeof (struct PeerCreateData));
157 data->host = host;
158 data->cfg = cfg;
103 data->cb = cb; 159 data->cb = cb;
104 data->cls = cls; 160 data->cls = cls;
105 data->peer = peer; 161 data->peer = peer;
106 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 162 opc = GNUNET_malloc (sizeof (struct OperationContext));
107 op->controller = controller; 163 opc->c = controller;
108 op->operation_id = controller->operation_counter++; 164 opc->data = data;
109 op->type = OP_PEER_CREATE; 165 opc->id = controller->operation_counter++;
110 op->data = data; 166 opc->type = OP_PEER_CREATE;
111 config = GNUNET_CONFIGURATION_serialize (cfg, &c_size); 167 opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create,
112 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); 168 &oprelease_peer_create);
113 GNUNET_free (config); 169 GNUNET_TESTBED_operation_queue_insert_ (controller->opq_peer_create, opc->op);
114 msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage); 170 return opc->op;
115 msg = GNUNET_realloc (xconfig, msize);
116 memmove (&msg[1], msg, xc_size); /* Move the compressed config */
117 msg->header.size = htons (msize);
118 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
119 msg->operation_id = GNUNET_htonll (op->operation_id);
120 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host));
121 msg->peer_id = htonl (peer->unique_id);
122 msg->config_size = htonl (c_size);
123 GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
124 peer->controller->op_tail, op);
125 GNUNET_TESTBED_queue_message_ (controller,
126 (struct GNUNET_MessageHeader *) msg);
127 return op;
128} 171}
129 172
130 173
@@ -151,7 +194,8 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
151 * 194 *
152 * @param controller controller process to use 195 * @param controller controller process to use
153 * @param host host to run the peer on 196 * @param host host to run the peer on
154 * @param cfg configuration to use for the peer 197 * @param cfg Template configuration to use for the peer. Should exist until
198 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
155 * @param cb the callback to call when the peer has been created 199 * @param cb the callback to call when the peer has been created
156 * @param cls the closure to the above callback 200 * @param cls the closure to the above callback
157 * @return the operation handle 201 * @return the operation handle
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index 9c1305c79..e7c1e9136 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -115,7 +115,17 @@ struct GNUNET_TESTBED_Peer
115struct PeerCreateData 115struct PeerCreateData
116{ 116{
117 /** 117 /**
118 * THe call back to call when we receive peer create success message 118 * The host where the peer has to be created
119 */
120 struct GNUNET_TESTBED_Host *host;
121
122 /**
123 * The template configuration of the peer
124 */
125 const struct GNUNET_CONFIGURATION_Handle *cfg;
126
127 /**
128 * The call back to call when we receive peer create success message
119 */ 129 */
120 GNUNET_TESTBED_PeerCreateCallback cb; 130 GNUNET_TESTBED_PeerCreateCallback cb;
121 131