summaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_peers.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-31 18:48:06 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-31 18:48:06 +0000
commit94c672c467be073e9b62fe2c1b45267163f74db5 (patch)
tree837418d6d890d930e3444c48f62554c394301a38 /src/testbed/testbed_api_peers.c
parente7cbb8d414b22af3d41759170e9bfad198dd9774 (diff)
downloadgnunet-94c672c467be073e9b62fe2c1b45267163f74db5.tar.gz
gnunet-94c672c467be073e9b62fe2c1b45267163f74db5.zip
peer start/stop with new operations handling
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r--src/testbed/testbed_api_peers.c138
1 files changed, 102 insertions, 36 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 4f9fa768c..ca4e46e39 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -112,8 +112,7 @@ opstart_peer_destroy (void *cls)
112 msg->operation_id = GNUNET_htonll (opc->id); 112 msg->operation_id = GNUNET_htonll (opc->id);
113 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, 113 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head,
114 opc->c->ocq_tail, opc); 114 opc->c->ocq_tail, opc);
115 GNUNET_TESTBED_queue_message_ (peer->controller, 115 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
116 (struct GNUNET_MessageHeader *) msg);
117} 116}
118 117
119 118
@@ -133,6 +132,87 @@ oprelease_peer_destroy (void *cls)
133 132
134 133
135/** 134/**
135 * Function to called when a peer start operation is ready
136 *
137 * @param cls the closure from GNUNET_TESTBED_operation_create_()
138 */
139static void
140opstart_peer_start (void *cls)
141{
142 struct OperationContext *opc = cls;
143 struct GNUNET_TESTBED_PeerStartMessage *msg;
144 struct GNUNET_TESTBED_Peer *peer;
145
146 GNUNET_assert (OP_PEER_START == opc->type);
147 GNUNET_assert (NULL != opc->data);
148 peer = opc->data;
149 GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state));
150 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
151 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
152 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER);
153 msg->peer_id = htonl (peer->unique_id);
154 msg->operation_id = GNUNET_htonll (opc->id);
155 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
156 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
157}
158
159
160/**
161 * Callback which will be called when peer start type operation is released
162 *
163 * @param cls the closure from GNUNET_TESTBED_operation_create_()
164 */
165static void
166oprelease_peer_start (void *cls)
167{
168 struct OperationContext *opc = cls;
169
170 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
171 GNUNET_free (opc);
172}
173
174
175/**
176 * Function to called when a peer stop operation is ready
177 *
178 * @param cls the closure from GNUNET_TESTBED_operation_create_()
179 */
180static void
181opstart_peer_stop (void *cls)
182{
183 struct OperationContext *opc = cls;
184 struct GNUNET_TESTBED_PeerStopMessage *msg;
185 struct GNUNET_TESTBED_Peer *peer;
186
187 GNUNET_assert (NULL != opc->data);
188 peer = opc->data;
189 GNUNET_assert (PS_STARTED == peer->state);
190 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
191 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER);
192 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
193 msg->peer_id = htonl (peer->unique_id);
194 msg->operation_id = GNUNET_htonll (opc->id);
195 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
196 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
197}
198
199
200/**
201 * Callback which will be called when peer stop type operation is released
202 *
203 * @param cls the closure from GNUNET_TESTBED_operation_create_()
204 */
205static void
206oprelease_peer_stop (void *cls)
207{
208 struct OperationContext *opc = cls;
209
210 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
211 GNUNET_free (opc);
212}
213
214
215/**
136 * Lookup a peer by ID. 216 * Lookup a peer by ID.
137 * 217 *
138 * @param id global peer ID assigned to the peer 218 * @param id global peer ID assigned to the peer
@@ -268,24 +348,17 @@ GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
268struct GNUNET_TESTBED_Operation * 348struct GNUNET_TESTBED_Operation *
269GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer) 349GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
270{ 350{
271 struct GNUNET_TESTBED_Operation *op; 351 struct OperationContext *opc;
272 struct GNUNET_TESTBED_PeerStartMessage *msg;
273 352
274 GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state)); 353 opc = GNUNET_malloc (sizeof (struct OperationContext));
275 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 354 opc->c = peer->controller;
276 op->operation_id = peer->controller->operation_counter++; 355 opc->data = peer;
277 op->controller = peer->controller; 356 opc->id = opc->c->operation_counter++;
278 op->type = OP_PEER_START; 357 opc->type = OP_PEER_START;
279 op->data = peer; 358 opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start,
280 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); 359 &oprelease_peer_start);
281 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); 360 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
282 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER); 361 return opc->op;
283 msg->peer_id = htonl (peer->unique_id);
284 msg->operation_id = GNUNET_htonll (op->operation_id);
285 GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
286 peer->controller->op_tail, op);
287 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
288 return op;
289} 362}
290 363
291 364
@@ -300,24 +373,17 @@ GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
300struct GNUNET_TESTBED_Operation * 373struct GNUNET_TESTBED_Operation *
301GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer) 374GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
302{ 375{
303 struct GNUNET_TESTBED_Operation *op; 376 struct OperationContext *opc;
304 struct GNUNET_TESTBED_PeerStopMessage *msg;
305 377
306 GNUNET_assert (PS_STARTED == peer->state); 378 opc = GNUNET_malloc (sizeof (struct OperationContext));
307 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 379 opc->c = peer->controller;
308 op->operation_id = peer->controller->operation_counter++; 380 opc->data = peer;
309 op->controller = peer->controller; 381 opc->id = opc->c->operation_counter++;
310 op->type = OP_PEER_STOP; 382 opc->type = OP_PEER_STOP;
311 op->data = peer; 383 opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop,
312 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); 384 &oprelease_peer_stop);
313 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER); 385 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
314 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); 386 return opc->op;
315 msg->peer_id = htonl (peer->unique_id);
316 msg->operation_id = GNUNET_htonll (op->operation_id);
317 GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
318 peer->controller->op_tail, op);
319 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
320 return op;
321} 387}
322 388
323 389