aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r--src/testbed/testbed_api_peers.c75
1 files changed, 54 insertions, 21 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 3ecb38325..4f9fa768c 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -91,6 +91,48 @@ oprelease_peer_create (void *cls)
91 91
92 92
93/** 93/**
94 * Function to called when a peer destroy operation is ready
95 *
96 * @param cls the closure from GNUNET_TESTBED_operation_create_()
97 */
98static void
99opstart_peer_destroy (void *cls)
100{
101 struct OperationContext *opc = cls;
102 struct GNUNET_TESTBED_Peer *peer;
103 struct GNUNET_TESTBED_PeerDestroyMessage *msg;
104
105 GNUNET_assert (OP_PEER_DESTROY == opc->type);
106 peer = opc->data;
107 GNUNET_assert (NULL != peer);
108 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
109 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
110 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
111 msg->peer_id = htonl (peer->unique_id);
112 msg->operation_id = GNUNET_htonll (opc->id);
113 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head,
114 opc->c->ocq_tail, opc);
115 GNUNET_TESTBED_queue_message_ (peer->controller,
116 (struct GNUNET_MessageHeader *) msg);
117}
118
119
120/**
121 * Callback which will be called when peer_create type operation is released
122 *
123 * @param cls the closure from GNUNET_TESTBED_operation_create_()
124 */
125static void
126oprelease_peer_destroy (void *cls)
127{
128 struct OperationContext *opc = cls;
129
130 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
131 GNUNET_free (opc);
132}
133
134
135/**
94 * Lookup a peer by ID. 136 * Lookup a peer by ID.
95 * 137 *
96 * @param id global peer ID assigned to the peer 138 * @param id global peer ID assigned to the peer
@@ -347,27 +389,18 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
347struct GNUNET_TESTBED_Operation * 389struct GNUNET_TESTBED_Operation *
348GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) 390GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
349{ 391{
350 struct GNUNET_TESTBED_Operation *op; 392 struct OperationContext *opc;
351 struct PeerDestroyData *data; 393
352 struct GNUNET_TESTBED_PeerDestroyMessage *msg; 394 opc = GNUNET_malloc (sizeof (struct OperationContext));
353 395 opc->data = peer;
354 data = GNUNET_malloc (sizeof (struct PeerDestroyData)); 396 opc->c = peer->controller;
355 data->peer = peer; 397 opc->id = peer->controller->operation_counter++;
356 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 398 opc->type = OP_PEER_DESTROY;
357 op->operation_id = peer->controller->operation_counter++; 399 opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy,
358 op->controller = peer->controller; 400 &oprelease_peer_destroy);
359 op->type = OP_PEER_DESTROY; 401 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create,
360 op->data = data; 402 opc->op);
361 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); 403 return opc->op;
362 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
363 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
364 msg->peer_id = htonl (peer->unique_id);
365 msg->operation_id = GNUNET_htonll (op->operation_id);
366 GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
367 peer->controller->op_tail, op);
368 GNUNET_TESTBED_queue_message_ (peer->controller,
369 (struct GNUNET_MessageHeader *) msg);
370 return op;
371} 404}
372 405
373 406