aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-20 12:02:27 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-20 12:02:27 +0000
commit15f4d07a0a03d4c2358c92976cca4708fcca7ff4 (patch)
tree16b30b28c0e2564447d72725c758c47b14698129
parenta5d6aecaeb8fac43d885d5e8cfad3d33b8f271b4 (diff)
downloadgnunet-15f4d07a0a03d4c2358c92976cca4708fcca7ff4.tar.gz
gnunet-15f4d07a0a03d4c2358c92976cca4708fcca7ff4.zip
peer create callback
-rw-r--r--src/include/gnunet_testbed_service.h26
-rw-r--r--src/testbed/gnunet-service-testbed.c39
-rw-r--r--src/testbed/test_testbed_api.c28
-rw-r--r--src/testbed/test_testbed_api_2peers.c28
-rw-r--r--src/testbed/testbed.h5
-rw-r--r--src/testbed/testbed_api.c28
-rw-r--r--src/testbed/testbed_api.h5
-rw-r--r--src/testbed/testbed_api_peers.c38
-rw-r--r--src/testbed/testbed_api_peers.h35
9 files changed, 189 insertions, 43 deletions
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
index d6c4354fe..19928623f 100644
--- a/src/include/gnunet_testbed_service.h
+++ b/src/include/gnunet_testbed_service.h
@@ -612,7 +612,21 @@ GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
612 const char *sxcfg, 612 const char *sxcfg,
613 size_t sxcfg_size, 613 size_t sxcfg_size,
614 size_t scfg_size, 614 size_t scfg_size,
615 int is_subordinate); 615 int is_subordinate);
616
617
618/**
619 * Functions of this signature are called when a peer has been successfully
620 * created
621 *
622 * @param cls the closure from GNUNET_TESTBED_peer_create()
623 * @param peer the handle for the created peer; NULL on any error during
624 * creation
625 * @param emsg NULL if peer is not NULL; else MAY contain the error description
626 */
627typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
628 struct GNUNET_TESTBED_Peer *peer,
629 const char *emsg);
616 630
617 631
618/** 632/**
@@ -639,12 +653,16 @@ GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
639 * @param controller controller process to use 653 * @param controller controller process to use
640 * @param host host to run the peer on 654 * @param host host to run the peer on
641 * @param cfg configuration to use for the peer 655 * @param cfg configuration to use for the peer
642 * @return handle to the peer (actual startup will happen asynchronously) 656 * @param cb the callback to call when the peer has been created
657 * @param cls the closure to the above callback
658 * @return the operation handle
643 */ 659 */
644struct GNUNET_TESTBED_Peer * 660struct GNUNET_TESTBED_Operation *
645GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, 661GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
646 struct GNUNET_TESTBED_Host *host, 662 struct GNUNET_TESTBED_Host *host,
647 const struct GNUNET_CONFIGURATION_Handle *cfg); 663 const struct GNUNET_CONFIGURATION_Handle *cfg,
664 GNUNET_TESTBED_PeerCreateCallback cb,
665 void *cls);
648 666
649 667
650/** 668/**
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index ef4a5838f..b0fb72228 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -1157,6 +1157,7 @@ handle_peer_create (void *cls,
1157 const struct GNUNET_MessageHeader *message) 1157 const struct GNUNET_MessageHeader *message)
1158{ 1158{
1159 const struct GNUNET_TESTBED_PeerCreateMessage *msg; 1159 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1160 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1160 struct GNUNET_CONFIGURATION_Handle *cfg; 1161 struct GNUNET_CONFIGURATION_Handle *cfg;
1161 char *config; 1162 char *config;
1162 size_t dest_size; 1163 size_t dest_size;
@@ -1224,6 +1225,12 @@ handle_peer_create (void *cls,
1224 return; 1225 return;
1225 } 1226 }
1226 peer_list_add (peer); 1227 peer_list_add (peer);
1228 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1229 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1230 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
1231 reply->peer_id = msg->peer_id;
1232 reply->operation_id = msg->operation_id;
1233 queue_message (client, &reply->header);
1227 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1234 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1228 return; 1235 return;
1229 } 1236 }
@@ -1284,6 +1291,7 @@ handle_peer_destroy (void *cls,
1284 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS); 1291 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
1285 reply->header.size = htons (reply_size); 1292 reply->header.size = htons (reply_size);
1286 reply->operation_id = msg->operation_id; 1293 reply->operation_id = msg->operation_id;
1294 reply->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
1287 queue_message (client, &reply->header); 1295 queue_message (client, &reply->header);
1288 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1296 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1289} 1297}
@@ -1302,7 +1310,7 @@ handle_peer_start (void *cls,
1302 const struct GNUNET_MessageHeader *message) 1310 const struct GNUNET_MessageHeader *message)
1303{ 1311{
1304 const struct GNUNET_TESTBED_PeerStartMessage *msg; 1312 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1305 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply; 1313 struct GNUNET_TESTBED_PeerEventMessage *reply;
1306 uint32_t peer_id; 1314 uint32_t peer_id;
1307 1315
1308 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message; 1316 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
@@ -1316,10 +1324,19 @@ handle_peer_start (void *cls,
1316 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1324 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1317 return; 1325 return;
1318 } 1326 }
1319 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)); 1327 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer_list[peer_id]->peer))
1320 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)); 1328 {
1321 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS); 1329 /* FIXME: return FAILURE message */
1322 reply->peer_id = htonl (peer_id); 1330 GNUNET_break (0);
1331 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1332 return;
1333 }
1334 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1335 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
1336 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1337 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
1338 reply->host_id = htonl (master_context->host_id);
1339 reply->peer_id = msg->peer_id;
1323 reply->operation_id = msg->operation_id; 1340 reply->operation_id = msg->operation_id;
1324 queue_message (client, &reply->header); 1341 queue_message (client, &reply->header);
1325 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1342 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1339,7 +1356,7 @@ handle_peer_stop (void *cls,
1339 const struct GNUNET_MessageHeader *message) 1356 const struct GNUNET_MessageHeader *message)
1340{ 1357{
1341 const struct GNUNET_TESTBED_PeerStopMessage *msg; 1358 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1342 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *reply; 1359 struct GNUNET_TESTBED_PeerEventMessage *reply;
1343 uint32_t peer_id; 1360 uint32_t peer_id;
1344 1361
1345 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message; 1362 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
@@ -1357,11 +1374,13 @@ handle_peer_stop (void *cls,
1357 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1374 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1358 return; 1375 return;
1359 } 1376 }
1360 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage)); 1377 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1361 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS); 1378 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
1362 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage)); 1379 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1363 reply->operation_id = msg->operation_id;
1364 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP); 1380 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
1381 reply->host_id = htonl (master_context->host_id);
1382 reply->peer_id = msg->peer_id;
1383 reply->operation_id = msg->operation_id;
1365 queue_message (client, &reply->header); 1384 queue_message (client, &reply->header);
1366 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1385 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1367} 1386}
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c
index 6378fd9cc..3ae6dbd67 100644
--- a/src/testbed/test_testbed_api.c
+++ b/src/testbed/test_testbed_api.c
@@ -153,6 +153,30 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
153 153
154 154
155/** 155/**
156 * Functions of this signature are called when a peer has been successfully
157 * created
158 *
159 * @param cls the closure from GNUNET_TESTBED_peer_create()
160 * @param peer the handle for the created peer; NULL on any error during
161 * creation
162 * @param emsg NULL if peer is not NULL; else MAY contain the error description
163 */
164static void
165peer_create_cb (void *cls,
166 struct GNUNET_TESTBED_Peer *peer, const char *emsg)
167{
168 struct GNUNET_TESTBED_Peer **peer_ptr;
169
170 peer_ptr = cls;
171 GNUNET_assert (NULL != peer);
172 GNUNET_assert (NULL != peer_ptr);
173 *peer_ptr = peer;
174 operation = GNUNET_TESTBED_peer_destroy (peer);
175 GNUNET_assert (NULL != operation);
176}
177
178
179/**
156 * Callback which will be called to after a host registration succeeded or failed 180 * Callback which will be called to after a host registration succeeded or failed
157 * 181 *
158 * @param cls the host which has been registered 182 * @param cls the host which has been registered
@@ -163,9 +187,7 @@ registration_comp (void *cls, const char *emsg)
163{ 187{
164 GNUNET_assert (cls == neighbour); 188 GNUNET_assert (cls == neighbour);
165 reg_handle = NULL; 189 reg_handle = NULL;
166 peer = GNUNET_TESTBED_peer_create (controller, host, cfg); 190 operation = GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb, &peer);
167 GNUNET_assert (NULL != peer);
168 operation = GNUNET_TESTBED_peer_destroy (peer);
169 GNUNET_assert (NULL != operation); 191 GNUNET_assert (NULL != operation);
170} 192}
171 193
diff --git a/src/testbed/test_testbed_api_2peers.c b/src/testbed/test_testbed_api_2peers.c
index 9f55b61eb..c8422ba9d 100644
--- a/src/testbed/test_testbed_api_2peers.c
+++ b/src/testbed/test_testbed_api_2peers.c
@@ -154,6 +154,30 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
154 154
155 155
156/** 156/**
157 * Functions of this signature are called when a peer has been successfully
158 * created
159 *
160 * @param cls the closure from GNUNET_TESTBED_peer_create()
161 * @param peer the handle for the created peer; NULL on any error during
162 * creation
163 * @param emsg NULL if peer is not NULL; else MAY contain the error description
164 */
165static void
166peer_create_cb (void *cls,
167 struct GNUNET_TESTBED_Peer *peer, const char *emsg)
168{
169 struct GNUNET_TESTBED_Peer **peer_ptr;
170
171 peer_ptr = cls;
172 GNUNET_assert (NULL != peer);
173 GNUNET_assert (NULL != peer_ptr);
174 *peer_ptr = peer;
175 operation = GNUNET_TESTBED_peer_destroy (peer);
176 GNUNET_assert (NULL != operation);
177}
178
179
180/**
157 * Callback which will be called to after a host registration succeeded or failed 181 * Callback which will be called to after a host registration succeeded or failed
158 * 182 *
159 * @param cls the host which has been registered 183 * @param cls the host which has been registered
@@ -164,9 +188,7 @@ registration_comp (void *cls, const char *emsg)
164{ 188{
165 GNUNET_assert (cls == neighbour); 189 GNUNET_assert (cls == neighbour);
166 reg_handle = NULL; 190 reg_handle = NULL;
167 peer = GNUNET_TESTBED_peer_create (controller, host, cfg); 191 operation = GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb, &peer);
168 GNUNET_assert (NULL != peer);
169 operation = GNUNET_TESTBED_peer_destroy (peer);
170 GNUNET_assert (NULL != operation); 192 GNUNET_assert (NULL != operation);
171} 193}
172 194
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h
index fff76f2ec..a2bb77e3d 100644
--- a/src/testbed/testbed.h
+++ b/src/testbed/testbed.h
@@ -198,6 +198,11 @@ struct GNUNET_TESTBED_PeerCreateMessage
198 struct GNUNET_MessageHeader header; 198 struct GNUNET_MessageHeader header;
199 199
200 /** 200 /**
201 * Unique operation id
202 */
203 uint64_t operation_id GNUNET_PACKED;
204
205 /**
201 * On which host should the peer be started? 206 * On which host should the peer be started?
202 */ 207 */
203 uint32_t host_id GNUNET_PACKED; 208 uint32_t host_id GNUNET_PACKED;
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index e343daa31..f7d58e9bb 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -300,7 +300,10 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
300 GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg) 300 GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg)
301{ 301{
302 struct GNUNET_TESTBED_Operation *op; 302 struct GNUNET_TESTBED_Operation *op;
303 struct PeerCreateData *data;
303 struct GNUNET_TESTBED_Peer *peer; 304 struct GNUNET_TESTBED_Peer *peer;
305 GNUNET_TESTBED_PeerCreateCallback cb;
306 void *cls;
304 uint64_t op_id; 307 uint64_t op_id;
305 308
306 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) 309 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)
@@ -311,21 +314,24 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
311 if (op->operation_id == op_id) 314 if (op->operation_id == op_id)
312 break; 315 break;
313 } 316 }
314 GNUNET_assert (NULL != op); 317 if (NULL == op)
315 peer = op->data;
316 GNUNET_assert (NULL != peer);
317 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
318 if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_PEER_START)))
319 { 318 {
320 struct GNUNET_TESTBED_EventInformation info; 319 LOG_DEBUG ("Operation not found\n");
321 320 return GNUNET_YES;
322 info.details.peer_start.host = peer->host;
323 info.details.peer_start.peer = peer;
324 if (NULL != c->cc)
325 c->cc (c->cc_cls, &info);
326 } 321 }
322 GNUNET_assert (OP_PEER_CREATE == op->type);
323 GNUNET_assert (NULL != op->data);
324 data = op->data;
325 GNUNET_assert (NULL != data->peer);
326 peer = data->peer;
327 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
328 cb = data->cb;
329 cls = data->cls;
327 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); 330 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
331 GNUNET_free (data);
328 GNUNET_free (op); 332 GNUNET_free (op);
333 if (NULL != cb)
334 cb (cls, peer, NULL);
329 return GNUNET_YES; 335 return GNUNET_YES;
330} 336}
331 337
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index a01ea1c29..e83e21b52 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -34,6 +34,11 @@
34enum OperationType 34enum OperationType
35 { 35 {
36 /** 36 /**
37 * Peer create operation
38 */
39 OP_PEER_CREATE,
40
41 /**
37 * Peer start operation 42 * Peer start operation
38 */ 43 */
39 OP_PEER_START, 44 OP_PEER_START,
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 8beae14f9..0010105dc 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -72,15 +72,21 @@ GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id)
72 * @param controller controller process to use 72 * @param controller controller process to use
73 * @param host host to run the peer on 73 * @param host host to run the peer on
74 * @param cfg configuration to use for the peer 74 * @param cfg configuration to use for the peer
75 * @return handle to the peer (actual startup will happen asynchronously) 75 * @param cb the callback to call when the peer has been created
76 * @param cls the closure to the above callback
77 * @return the operation handle
76 */ 78 */
77struct GNUNET_TESTBED_Peer * 79struct GNUNET_TESTBED_Operation *
78GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, 80GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
79 struct GNUNET_TESTBED_Controller *controller, 81 struct GNUNET_TESTBED_Controller *controller,
80 struct GNUNET_TESTBED_Host *host, 82 struct GNUNET_TESTBED_Host *host,
81 const struct GNUNET_CONFIGURATION_Handle *cfg) 83 const struct GNUNET_CONFIGURATION_Handle *cfg,
84 GNUNET_TESTBED_PeerCreateCallback cb,
85 void *cls)
82{ 86{
83 struct GNUNET_TESTBED_Peer *peer; 87 struct GNUNET_TESTBED_Peer *peer;
88 struct PeerCreateData *data;
89 struct GNUNET_TESTBED_Operation *op;
84 struct GNUNET_TESTBED_PeerCreateMessage *msg; 90 struct GNUNET_TESTBED_PeerCreateMessage *msg;
85 char *config; 91 char *config;
86 char *xconfig; 92 char *xconfig;
@@ -92,6 +98,14 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
92 peer->controller = controller; 98 peer->controller = controller;
93 peer->host = host; 99 peer->host = host;
94 peer->unique_id = unique_id; 100 peer->unique_id = unique_id;
101 data = GNUNET_malloc (sizeof (struct PeerCreateData));
102 data->cb = cb;
103 data->cls = cls;
104 data->peer = peer;
105 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
106 op->operation_id = controller->operation_counter++;
107 op->type = OP_PEER_CREATE;
108 op->data = data;
95 config = GNUNET_CONFIGURATION_serialize (cfg, &c_size); 109 config = GNUNET_CONFIGURATION_serialize (cfg, &c_size);
96 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); 110 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
97 GNUNET_free (config); 111 GNUNET_free (config);
@@ -100,12 +114,15 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
100 memmove (&msg[1], msg, xc_size); /* Move the compressed config */ 114 memmove (&msg[1], msg, xc_size); /* Move the compressed config */
101 msg->header.size = htons (msize); 115 msg->header.size = htons (msize);
102 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER); 116 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
117 msg->operation_id = GNUNET_htonll (op->operation_id);
103 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host)); 118 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host));
104 msg->peer_id = htonl (peer->unique_id); 119 msg->peer_id = htonl (peer->unique_id);
105 msg->config_size = htonl (c_size); 120 msg->config_size = htonl (c_size);
121 GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
122 peer->controller->op_tail, op);
106 GNUNET_TESTBED_queue_message_ (controller, 123 GNUNET_TESTBED_queue_message_ (controller,
107 (struct GNUNET_MessageHeader *) msg); 124 (struct GNUNET_MessageHeader *) msg);
108 return peer; 125 return op;
109} 126}
110 127
111 128
@@ -133,19 +150,24 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
133 * @param controller controller process to use 150 * @param controller controller process to use
134 * @param host host to run the peer on 151 * @param host host to run the peer on
135 * @param cfg configuration to use for the peer 152 * @param cfg configuration to use for the peer
136 * @return handle to the peer (actual startup will happen asynchronously) 153 * @param cb the callback to call when the peer has been created
154 * @param cls the closure to the above callback
155 * @return the operation handle
137 */ 156 */
138struct GNUNET_TESTBED_Peer * 157struct GNUNET_TESTBED_Operation *
139GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, 158GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
140 struct GNUNET_TESTBED_Host *host, 159 struct GNUNET_TESTBED_Host *host,
141 const struct GNUNET_CONFIGURATION_Handle *cfg) 160 const struct GNUNET_CONFIGURATION_Handle *cfg,
161 GNUNET_TESTBED_PeerCreateCallback cb,
162 void *cls)
142{ 163{
143 static uint32_t id_gen; 164 static uint32_t id_gen;
144 165
145 return GNUNET_TESTBED_peer_create_with_id_ (++id_gen, 166 return GNUNET_TESTBED_peer_create_with_id_ (++id_gen,
146 controller, 167 controller,
147 host, 168 host,
148 cfg); 169 cfg,
170 cb, cls);
149} 171}
150 172
151 173
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index ee5ec3bd9..83d2d890f 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -79,6 +79,29 @@ struct GNUNET_TESTBED_Peer
79 79
80 80
81/** 81/**
82 * Data for the OperationType OP_PEER_CREATE
83 */
84struct PeerCreateData
85{
86 /**
87 * THe call back to call when we receive peer create success message
88 */
89 GNUNET_TESTBED_PeerCreateCallback cb;
90
91 /**
92 * The closure for the above callback
93 */
94 void *cls;
95
96 /**
97 * The peer structure to return when we get success message
98 */
99 struct GNUNET_TESTBED_Peer *peer;
100
101};
102
103
104/**
82 * Data for the OperationType OP_PEER_DESTROY; 105 * Data for the OperationType OP_PEER_DESTROY;
83 */ 106 */
84struct PeerDestroyData 107struct PeerDestroyData
@@ -119,13 +142,17 @@ struct PeerDestroyData
119 * @param controller controller process to use 142 * @param controller controller process to use
120 * @param host host to run the peer on 143 * @param host host to run the peer on
121 * @param cfg configuration to use for the peer 144 * @param cfg configuration to use for the peer
122 * @return handle to the peer (actual startup will happen asynchronously) 145 * @param cb the callback to call when the peer has been created
146 * @param cls the closure to the above callback
147 * @return the operation handle
123 */ 148 */
124struct GNUNET_TESTBED_Peer * 149struct GNUNET_TESTBED_Operation *
125GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, 150GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
126 struct GNUNET_TESTBED_Controller *controller, 151 struct GNUNET_TESTBED_Controller *controller,
127 struct GNUNET_TESTBED_Host *host, 152 struct GNUNET_TESTBED_Host *host,
128 const struct GNUNET_CONFIGURATION_Handle *cfg); 153 const struct GNUNET_CONFIGURATION_Handle *cfg,
154 GNUNET_TESTBED_PeerCreateCallback cb,
155 void *cls);
129 156
130 157
131 158