aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_peers.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-17 13:01:13 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-17 13:01:13 +0000
commitc5989d817871492bde9ee6df59db98901d4cf317 (patch)
tree8701d33982e686483ee29d0a8b5155c2806c38bd /src/testbed/testbed_api_peers.c
parent2b7a52a080e089e852b0a15da690b058e97bedc0 (diff)
downloadgnunet-c5989d817871492bde9ee6df59db98901d4cf317.tar.gz
gnunet-c5989d817871492bde9ee6df59db98901d4cf317.zip
- use hashmap for remembering active operation contexts
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r--src/testbed/testbed_api_peers.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index fe3fad601..8341a96a3 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -121,7 +121,7 @@ opstart_peer_create (void *cls)
121 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host)); 121 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host));
122 msg->peer_id = htonl (data->peer->unique_id); 122 msg->peer_id = htonl (data->peer->unique_id);
123 msg->config_size = htonl (c_size); 123 msg->config_size = htonl (c_size);
124 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); 124 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
125 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 125 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
126} 126}
127 127
@@ -139,7 +139,7 @@ oprelease_peer_create (void *cls)
139 switch (opc->state) 139 switch (opc->state)
140 { 140 {
141 case OPC_STATE_STARTED: 141 case OPC_STATE_STARTED:
142 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 142 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
143 /* No break we continue flow */ 143 /* No break we continue flow */
144 case OPC_STATE_INIT: 144 case OPC_STATE_INIT:
145 GNUNET_free (((struct PeerCreateData *) opc->data)->peer); 145 GNUNET_free (((struct PeerCreateData *) opc->data)->peer);
@@ -172,7 +172,7 @@ opstart_peer_destroy (void *cls)
172 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER); 172 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER);
173 msg->peer_id = htonl (peer->unique_id); 173 msg->peer_id = htonl (peer->unique_id);
174 msg->operation_id = GNUNET_htonll (opc->id); 174 msg->operation_id = GNUNET_htonll (opc->id);
175 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); 175 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
176 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); 176 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
177} 177}
178 178
@@ -190,7 +190,7 @@ oprelease_peer_destroy (void *cls)
190 switch (opc->state) 190 switch (opc->state)
191 { 191 {
192 case OPC_STATE_STARTED: 192 case OPC_STATE_STARTED:
193 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 193 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
194 /* no break; continue */ 194 /* no break; continue */
195 case OPC_STATE_INIT: 195 case OPC_STATE_INIT:
196 break; 196 break;
@@ -224,7 +224,7 @@ opstart_peer_start (void *cls)
224 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_START_PEER); 224 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_START_PEER);
225 msg->peer_id = htonl (peer->unique_id); 225 msg->peer_id = htonl (peer->unique_id);
226 msg->operation_id = GNUNET_htonll (opc->id); 226 msg->operation_id = GNUNET_htonll (opc->id);
227 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); 227 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
228 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); 228 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
229} 229}
230 230
@@ -242,7 +242,7 @@ oprelease_peer_start (void *cls)
242 switch (opc->state) 242 switch (opc->state)
243 { 243 {
244 case OPC_STATE_STARTED: 244 case OPC_STATE_STARTED:
245 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 245 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
246 /* no break; continue */ 246 /* no break; continue */
247 case OPC_STATE_INIT: 247 case OPC_STATE_INIT:
248 GNUNET_free (opc->data); 248 GNUNET_free (opc->data);
@@ -276,7 +276,7 @@ opstart_peer_stop (void *cls)
276 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); 276 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
277 msg->peer_id = htonl (peer->unique_id); 277 msg->peer_id = htonl (peer->unique_id);
278 msg->operation_id = GNUNET_htonll (opc->id); 278 msg->operation_id = GNUNET_htonll (opc->id);
279 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); 279 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
280 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); 280 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
281} 281}
282 282
@@ -294,7 +294,7 @@ oprelease_peer_stop (void *cls)
294 switch (opc->state) 294 switch (opc->state)
295 { 295 {
296 case OPC_STATE_STARTED: 296 case OPC_STATE_STARTED:
297 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 297 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
298 /* no break; continue */ 298 /* no break; continue */
299 case OPC_STATE_INIT: 299 case OPC_STATE_INIT:
300 GNUNET_free (opc->data); 300 GNUNET_free (opc->data);
@@ -349,7 +349,7 @@ opstart_peer_getinfo (void *cls)
349 msg = 349 msg =
350 GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, 350 GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id,
351 opc->id); 351 opc->id);
352 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); 352 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
353 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 353 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
354} 354}
355 355
@@ -368,7 +368,7 @@ oprelease_peer_getinfo (void *cls)
368 switch (opc->state) 368 switch (opc->state)
369 { 369 {
370 case OPC_STATE_STARTED: 370 case OPC_STATE_STARTED:
371 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 371 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
372 /* no break; continue */ 372 /* no break; continue */
373 case OPC_STATE_INIT: 373 case OPC_STATE_INIT:
374 GNUNET_free (opc->data); 374 GNUNET_free (opc->data);
@@ -419,7 +419,7 @@ opstart_overlay_connect (void *cls)
419 msg->peer2 = htonl (data->p2->unique_id); 419 msg->peer2 = htonl (data->p2->unique_id);
420 msg->operation_id = GNUNET_htonll (opc->id); 420 msg->operation_id = GNUNET_htonll (opc->id);
421 msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host)); 421 msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host));
422 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); 422 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
423 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 423 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
424} 424}
425 425
@@ -444,7 +444,7 @@ oprelease_overlay_connect (void *cls)
444 case OPC_STATE_STARTED: 444 case OPC_STATE_STARTED:
445 (void) GNUNET_TESTBED_release_time_slot_ (data->p1->host, data->tslot_index, 445 (void) GNUNET_TESTBED_release_time_slot_ (data->p1->host, data->tslot_index,
446 data); 446 data);
447 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 447 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
448 break; 448 break;
449 case OPC_STATE_FINISHED: 449 case OPC_STATE_FINISHED:
450 duration = GNUNET_TIME_absolute_get_duration (data->tstart); 450 duration = GNUNET_TIME_absolute_get_duration (data->tstart);
@@ -774,6 +774,11 @@ GNUNET_TESTBED_overlay_connect (void *op_cls,
774} 774}
775 775
776 776
777/**
778 * Function called when a peer manage service operation is ready
779 *
780 * @param cls the closure from GNUNET_TESTBED_operation_create_()
781 */
777static void 782static void
778opstart_manage_service (void *cls) 783opstart_manage_service (void *cls)
779{ 784{
@@ -793,11 +798,16 @@ opstart_manage_service (void *cls)
793 GNUNET_free (data->service_name); 798 GNUNET_free (data->service_name);
794 data->service_name = NULL; 799 data->service_name = NULL;
795 opc->state = OPC_STATE_STARTED; 800 opc->state = OPC_STATE_STARTED;
796 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); 801 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
797 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 802 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
798} 803}
799 804
800 805
806/**
807 * Callback which will be called when peer manage server operation is released
808 *
809 * @param cls the closure from GNUNET_TESTBED_operation_create_()
810 */
801static void 811static void
802oprelease_manage_service (void *cls) 812oprelease_manage_service (void *cls)
803{ 813{
@@ -808,7 +818,7 @@ oprelease_manage_service (void *cls)
808 switch (opc->state) 818 switch (opc->state)
809 { 819 {
810 case OPC_STATE_STARTED: 820 case OPC_STATE_STARTED:
811 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 821 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
812 break; 822 break;
813 case OPC_STATE_INIT: 823 case OPC_STATE_INIT:
814 GNUNET_assert (NULL != data); 824 GNUNET_assert (NULL != data);
@@ -822,6 +832,21 @@ oprelease_manage_service (void *cls)
822} 832}
823 833
824 834
835/**
836 * Start or stop given service at a peer. This should not be called to
837 * start/stop the peer's ARM service. Use GNUNET_TESTBED_peer_start(),
838 * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service. Success
839 * or failure of the generated operation is signalled through the controller
840 * event callback and/or operation completion callback.
841 *
842 * @param op_cls the closure for the operation
843 * @param peer the peer whose service is to be started/stopped
844 * @param service_name the name of the service
845 * @param cb the operation completion callback
846 * @param cb_cls the closure for the operation completion callback
847 * @param start 1 to start the service; 0 to stop the service
848 * @return an operation handle; NULL upon error (peer not running)
849 */
825struct GNUNET_TESTBED_Operation * 850struct GNUNET_TESTBED_Operation *
826GNUNET_TESTBED_peer_manage_service (void *op_cls, 851GNUNET_TESTBED_peer_manage_service (void *op_cls,
827 struct GNUNET_TESTBED_Peer *peer, 852 struct GNUNET_TESTBED_Peer *peer,