summaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet-service-testbed_peers.c')
-rw-r--r--src/testbed/gnunet-service-testbed_peers.c1591
1 files changed, 801 insertions, 790 deletions
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c
index 743c7e849..836f05464 100644
--- a/src/testbed/gnunet-service-testbed_peers.c
+++ b/src/testbed/gnunet-service-testbed_peers.c
@@ -44,7 +44,8 @@ unsigned int GST_num_local_peers;
44/** 44/**
45 * Context information to manage peers' services 45 * Context information to manage peers' services
46 */ 46 */
47struct ManageServiceContext { 47struct ManageServiceContext
48{
48 /** 49 /**
49 * DLL next ptr 50 * DLL next ptr
50 */ 51 */
@@ -96,7 +97,8 @@ struct ManageServiceContext {
96/** 97/**
97 * Context information for peer re-configure operations 98 * Context information for peer re-configure operations
98 */ 99 */
99struct PeerReconfigureContext { 100struct PeerReconfigureContext
101{
100 /** 102 /**
101 * DLL next for inclusoin in peer reconfigure operations list 103 * DLL next for inclusoin in peer reconfigure operations list
102 */ 104 */
@@ -164,11 +166,11 @@ static struct ManageServiceContext *mctx_tail;
164 * @param peer the peer to add 166 * @param peer the peer to add
165 */ 167 */
166static void 168static void
167peer_list_add(struct Peer *peer) 169peer_list_add (struct Peer *peer)
168{ 170{
169 if (peer->id >= GST_peer_list_size) 171 if (peer->id >= GST_peer_list_size)
170 GST_array_grow_large_enough(GST_peer_list, GST_peer_list_size, peer->id); 172 GST_array_grow_large_enough (GST_peer_list, GST_peer_list_size, peer->id);
171 GNUNET_assert(NULL == GST_peer_list[peer->id]); 173 GNUNET_assert (NULL == GST_peer_list[peer->id]);
172 GST_peer_list[peer->id] = peer; 174 GST_peer_list[peer->id] = peer;
173 if (GNUNET_NO == peer->is_remote) 175 if (GNUNET_NO == peer->is_remote)
174 GST_num_local_peers++; 176 GST_num_local_peers++;
@@ -181,7 +183,7 @@ peer_list_add(struct Peer *peer)
181 * @param peer the peer to be removed 183 * @param peer the peer to be removed
182 */ 184 */
183static void 185static void
184peer_list_remove(struct Peer *peer) 186peer_list_remove (struct Peer *peer)
185{ 187{
186 unsigned int orig_size; 188 unsigned int orig_size;
187 uint32_t id; 189 uint32_t id;
@@ -191,21 +193,21 @@ peer_list_remove(struct Peer *peer)
191 GST_peer_list[peer->id] = NULL; 193 GST_peer_list[peer->id] = NULL;
192 orig_size = GST_peer_list_size; 194 orig_size = GST_peer_list_size;
193 while (GST_peer_list_size >= LIST_GROW_STEP) 195 while (GST_peer_list_size >= LIST_GROW_STEP)
194 { 196 {
195 for (id = GST_peer_list_size - 1; 197 for (id = GST_peer_list_size - 1;
196 (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); 198 (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX);
197 id--) 199 id--)
198 if (NULL != GST_peer_list[id]) 200 if (NULL != GST_peer_list[id])
199 break;
200 if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1))
201 break; 201 break;
202 GST_peer_list_size -= LIST_GROW_STEP; 202 if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1))
203 } 203 break;
204 GST_peer_list_size -= LIST_GROW_STEP;
205 }
204 if (orig_size == GST_peer_list_size) 206 if (orig_size == GST_peer_list_size)
205 return; 207 return;
206 GST_peer_list = 208 GST_peer_list =
207 GNUNET_realloc(GST_peer_list, 209 GNUNET_realloc (GST_peer_list,
208 sizeof(struct Peer *) * GST_peer_list_size); 210 sizeof(struct Peer *) * GST_peer_list_size);
209} 211}
210 212
211 213
@@ -216,12 +218,12 @@ peer_list_remove(struct Peer *peer)
216 * @param cls the FowardedOperationContext 218 * @param cls the FowardedOperationContext
217 */ 219 */
218static void 220static void
219peer_create_forward_timeout(void *cls) 221peer_create_forward_timeout (void *cls)
220{ 222{
221 struct ForwardedOperationContext *fopc = cls; 223 struct ForwardedOperationContext *fopc = cls;
222 224
223 GNUNET_free(fopc->cls); 225 GNUNET_free (fopc->cls);
224 GST_forwarded_operation_timeout(fopc); 226 GST_forwarded_operation_timeout (fopc);
225} 227}
226 228
227 229
@@ -233,19 +235,19 @@ peer_create_forward_timeout(void *cls)
233 * @param msg the peer create success message 235 * @param msg the peer create success message
234 */ 236 */
235static void 237static void
236peer_create_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) 238peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
237{ 239{
238 struct ForwardedOperationContext *fopc = cls; 240 struct ForwardedOperationContext *fopc = cls;
239 struct Peer *remote_peer; 241 struct Peer *remote_peer;
240 242
241 if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS) 243 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS)
242 { 244 {
243 GNUNET_assert(NULL != fopc->cls); 245 GNUNET_assert (NULL != fopc->cls);
244 remote_peer = fopc->cls; 246 remote_peer = fopc->cls;
245 peer_list_add(remote_peer); 247 peer_list_add (remote_peer);
246 } 248 }
247 GST_forwarded_operation_reply_relay(fopc, 249 GST_forwarded_operation_reply_relay (fopc,
248 msg); 250 msg);
249} 251}
250 252
251 253
@@ -255,24 +257,24 @@ peer_create_success_cb(void *cls, const struct GNUNET_MessageHeader *msg)
255 * @param peer the peer structure to destroy 257 * @param peer the peer structure to destroy
256 */ 258 */
257void 259void
258GST_destroy_peer(struct Peer *peer) 260GST_destroy_peer (struct Peer *peer)
259{ 261{
260 GNUNET_break(0 == peer->reference_cnt); 262 GNUNET_break (0 == peer->reference_cnt);
261 if (GNUNET_YES == peer->is_remote) 263 if (GNUNET_YES == peer->is_remote)
262 { 264 {
263 peer_list_remove(peer); 265 peer_list_remove (peer);
264 GNUNET_free(peer); 266 GNUNET_free (peer);
265 return; 267 return;
266 } 268 }
267 if (GNUNET_YES == peer->details.local.is_running) 269 if (GNUNET_YES == peer->details.local.is_running)
268 { 270 {
269 GNUNET_TESTING_peer_stop(peer->details.local.peer); 271 GNUNET_TESTING_peer_stop (peer->details.local.peer);
270 peer->details.local.is_running = GNUNET_NO; 272 peer->details.local.is_running = GNUNET_NO;
271 } 273 }
272 GNUNET_TESTING_peer_destroy(peer->details.local.peer); 274 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
273 GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); 275 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
274 peer_list_remove(peer); 276 peer_list_remove (peer);
275 GNUNET_free(peer); 277 GNUNET_free (peer);
276} 278}
277 279
278 280
@@ -282,20 +284,20 @@ GST_destroy_peer(struct Peer *peer)
282 * @param mctx the ManageServiceContext 284 * @param mctx the ManageServiceContext
283 */ 285 */
284static void 286static void
285cleanup_mctx(struct ManageServiceContext *mctx) 287cleanup_mctx (struct ManageServiceContext *mctx)
286{ 288{
287 mctx->expired = GNUNET_YES; 289 mctx->expired = GNUNET_YES;
288 GNUNET_CONTAINER_DLL_remove(mctx_head, 290 GNUNET_CONTAINER_DLL_remove (mctx_head,
289 mctx_tail, 291 mctx_tail,
290 mctx); 292 mctx);
291 GNUNET_ARM_disconnect(mctx->ah); 293 GNUNET_ARM_disconnect (mctx->ah);
292 GNUNET_assert(0 < mctx->peer->reference_cnt); 294 GNUNET_assert (0 < mctx->peer->reference_cnt);
293 mctx->peer->reference_cnt--; 295 mctx->peer->reference_cnt--;
294 if ((GNUNET_YES == mctx->peer->destroy_flag) && 296 if ((GNUNET_YES == mctx->peer->destroy_flag) &&
295 (0 == mctx->peer->reference_cnt)) 297 (0 == mctx->peer->reference_cnt))
296 GST_destroy_peer(mctx->peer); 298 GST_destroy_peer (mctx->peer);
297 GNUNET_free(mctx->service); 299 GNUNET_free (mctx->service);
298 GNUNET_free(mctx); 300 GNUNET_free (mctx);
299} 301}
300 302
301 303
@@ -306,10 +308,10 @@ cleanup_mctx(struct ManageServiceContext *mctx)
306 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 308 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
307 */ 309 */
308static int 310static int
309stop_peer(struct Peer *peer) 311stop_peer (struct Peer *peer)
310{ 312{
311 GNUNET_assert(GNUNET_NO == peer->is_remote); 313 GNUNET_assert (GNUNET_NO == peer->is_remote);
312 if (GNUNET_OK != GNUNET_TESTING_peer_kill(peer->details.local.peer)) 314 if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer))
313 return GNUNET_SYSERR; 315 return GNUNET_SYSERR;
314 peer->details.local.is_running = GNUNET_NO; 316 peer->details.local.is_running = GNUNET_NO;
315 return GNUNET_OK; 317 return GNUNET_OK;
@@ -322,25 +324,25 @@ stop_peer(struct Peer *peer)
322 * @param prc the PeerReconfigureContext 324 * @param prc the PeerReconfigureContext
323 */ 325 */
324static void 326static void
325cleanup_prc(struct PeerReconfigureContext *prc) 327cleanup_prc (struct PeerReconfigureContext *prc)
326{ 328{
327 struct Peer *peer; 329 struct Peer *peer;
328 330
329 if (VALID_PEER_ID(prc->peer_id)) 331 if (VALID_PEER_ID (prc->peer_id))
332 {
333 peer = GST_peer_list [prc->peer_id];
334 if (1 != prc->stopped)
330 { 335 {
331 peer = GST_peer_list [prc->peer_id]; 336 GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer);
332 if (1 != prc->stopped) 337 stop_peer (peer); /* Stop the peer synchronously */
333 {
334 GNUNET_TESTING_peer_stop_async_cancel(peer->details.local.peer);
335 stop_peer(peer); /* Stop the peer synchronously */
336 }
337 } 338 }
339 }
338 if (NULL != prc->cfg) 340 if (NULL != prc->cfg)
339 GNUNET_CONFIGURATION_destroy(prc->cfg); 341 GNUNET_CONFIGURATION_destroy (prc->cfg);
340 GNUNET_CONTAINER_DLL_remove(prc_head, 342 GNUNET_CONTAINER_DLL_remove (prc_head,
341 prc_tail, 343 prc_tail,
342 prc); 344 prc);
343 GNUNET_free(prc); 345 GNUNET_free (prc);
344} 346}
345 347
346 348
@@ -350,7 +352,7 @@ cleanup_prc(struct PeerReconfigureContext *prc)
350 * @param client the client that disconnected 352 * @param client the client that disconnected
351 */ 353 */
352void 354void
353GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client) 355GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client)
354{ 356{
355 struct ForwardedOperationContext *fopc; 357 struct ForwardedOperationContext *fopc;
356 struct ForwardedOperationContext *fopcn; 358 struct ForwardedOperationContext *fopcn;
@@ -360,28 +362,28 @@ GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client)
360 struct PeerReconfigureContext *prcn; 362 struct PeerReconfigureContext *prcn;
361 363
362 for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) 364 for (fopc = fopcq_head; NULL != fopc; fopc = fopcn)
365 {
366 fopcn = fopc->next;
367 if (client == fopc->client)
363 { 368 {
364 fopcn = fopc->next; 369 if (OP_PEER_CREATE == fopc->type)
365 if (client == fopc->client) 370 GNUNET_free (fopc->cls);
366 { 371 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
367 if (OP_PEER_CREATE == fopc->type) 372 GST_forwarded_operation_timeout (fopc);
368 GNUNET_free(fopc->cls);
369 GNUNET_SCHEDULER_cancel(fopc->timeout_task);
370 GST_forwarded_operation_timeout(fopc);
371 }
372 } 373 }
374 }
373 for (mctx = mctx_head; NULL != mctx; mctx = mctxn) 375 for (mctx = mctx_head; NULL != mctx; mctx = mctxn)
374 { 376 {
375 mctxn = mctx->next; 377 mctxn = mctx->next;
376 if (client == mctx->client) 378 if (client == mctx->client)
377 cleanup_mctx(mctx); 379 cleanup_mctx (mctx);
378 } 380 }
379 for (prc = prc_head; NULL != prc; prc = prcn) 381 for (prc = prc_head; NULL != prc; prc = prcn)
380 { 382 {
381 prcn = prc->next; 383 prcn = prc->next;
382 if (client == prc->client) 384 if (client == prc->client)
383 cleanup_prc(prc); 385 cleanup_prc (prc);
384 } 386 }
385} 387}
386 388
387 389
@@ -393,22 +395,22 @@ GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client)
393 * @param msg the peer create success message 395 * @param msg the peer create success message
394 */ 396 */
395static void 397static void
396peer_destroy_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) 398peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
397{ 399{
398 struct ForwardedOperationContext *fopc = cls; 400 struct ForwardedOperationContext *fopc = cls;
399 struct Peer *remote_peer; 401 struct Peer *remote_peer;
400 402
401 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS == 403 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS ==
402 ntohs(msg->type)) 404 ntohs (msg->type))
403 { 405 {
404 remote_peer = fopc->cls; 406 remote_peer = fopc->cls;
405 GNUNET_assert(NULL != remote_peer); 407 GNUNET_assert (NULL != remote_peer);
406 remote_peer->destroy_flag = GNUNET_YES; 408 remote_peer->destroy_flag = GNUNET_YES;
407 if (0 == remote_peer->reference_cnt) 409 if (0 == remote_peer->reference_cnt)
408 GST_destroy_peer(remote_peer); 410 GST_destroy_peer (remote_peer);
409 } 411 }
410 GST_forwarded_operation_reply_relay(fopc, 412 GST_forwarded_operation_reply_relay (fopc,
411 msg); 413 msg);
412} 414}
413 415
414 416
@@ -420,8 +422,8 @@ peer_destroy_success_cb(void *cls, const struct GNUNET_MessageHeader *msg)
420 * @return #GNUNET_OK if @a msg is well-formed 422 * @return #GNUNET_OK if @a msg is well-formed
421 */ 423 */
422int 424int
423check_peer_create(void *cls, 425check_peer_create (void *cls,
424 const struct GNUNET_TESTBED_PeerCreateMessage *msg) 426 const struct GNUNET_TESTBED_PeerCreateMessage *msg)
425{ 427{
426 return GNUNET_OK; /* checked later */ 428 return GNUNET_OK; /* checked later */
427} 429}
@@ -434,8 +436,8 @@ check_peer_create(void *cls,
434 * @param msg the actual message 436 * @param msg the actual message
435 */ 437 */
436void 438void
437handle_peer_create(void *cls, 439handle_peer_create (void *cls,
438 const struct GNUNET_TESTBED_PeerCreateMessage *msg) 440 const struct GNUNET_TESTBED_PeerCreateMessage *msg)
439{ 441{
440 struct GNUNET_SERVICE_Client *client = cls; 442 struct GNUNET_SERVICE_Client *client = cls;
441 struct GNUNET_MQ_Envelope *env; 443 struct GNUNET_MQ_Envelope *env;
@@ -448,114 +450,114 @@ handle_peer_create(void *cls,
448 uint32_t host_id; 450 uint32_t host_id;
449 uint32_t peer_id; 451 uint32_t peer_id;
450 452
451 host_id = ntohl(msg->host_id); 453 host_id = ntohl (msg->host_id);
452 peer_id = ntohl(msg->peer_id); 454 peer_id = ntohl (msg->peer_id);
453 if (VALID_PEER_ID(peer_id)) 455 if (VALID_PEER_ID (peer_id))
454 { 456 {
455 (void)GNUNET_asprintf(&emsg, 457 (void) GNUNET_asprintf (&emsg,
456 "Peer with ID %u already exists", 458 "Peer with ID %u already exists",
457 peer_id); 459 peer_id);
458 GST_send_operation_fail_msg(client, 460 GST_send_operation_fail_msg (client,
459 GNUNET_ntohll(msg->operation_id), 461 GNUNET_ntohll (msg->operation_id),
460 emsg); 462 emsg);
461 GNUNET_free(emsg); 463 GNUNET_free (emsg);
462 GNUNET_SERVICE_client_continue(client); 464 GNUNET_SERVICE_client_continue (client);
463 return; 465 return;
464 } 466 }
465 if (UINT32_MAX == peer_id) 467 if (UINT32_MAX == peer_id)
468 {
469 GST_send_operation_fail_msg (client,
470 GNUNET_ntohll (msg->operation_id),
471 "Cannot create peer with given ID");
472 GNUNET_SERVICE_client_continue (client);
473 return;
474 }
475 if (host_id == GST_context->host_id)
476 {
477 /* We are responsible for this peer */
478 cfg = GNUNET_TESTBED_extract_config_ (&msg->header);
479 if (NULL == cfg)
466 { 480 {
467 GST_send_operation_fail_msg(client, 481 GNUNET_break (0);
468 GNUNET_ntohll(msg->operation_id), 482 GNUNET_SERVICE_client_drop (client);
469 "Cannot create peer with given ID");
470 GNUNET_SERVICE_client_continue(client);
471 return; 483 return;
472 } 484 }
473 if (host_id == GST_context->host_id) 485 GNUNET_CONFIGURATION_set_value_number (cfg,
486 "TESTBED",
487 "PEERID",
488 (unsigned long long) peer_id);
489
490 GNUNET_CONFIGURATION_set_value_number (cfg,
491 "PATHS",
492 "PEERID",
493 (unsigned long long) peer_id);
494 peer = GNUNET_new (struct Peer);
495 peer->is_remote = GNUNET_NO;
496 peer->details.local.cfg = cfg;
497 peer->id = peer_id;
498 LOG_DEBUG ("Creating peer with id: %u\n",
499 (unsigned int) peer->id);
500 peer->details.local.peer =
501 GNUNET_TESTING_peer_configure (GST_context->system,
502 peer->details.local.cfg, peer->id,
503 NULL /* Peer id */,
504 &emsg);
505 if (NULL == peer->details.local.peer)
474 { 506 {
475 /* We are responsible for this peer */ 507 LOG (GNUNET_ERROR_TYPE_WARNING,
476 cfg = GNUNET_TESTBED_extract_config_(&msg->header); 508 "Configuring peer failed: %s\n",
477 if (NULL == cfg) 509 emsg);
478 { 510 GNUNET_free (emsg);
479 GNUNET_break(0); 511 GNUNET_free (peer);
480 GNUNET_SERVICE_client_drop(client); 512 GNUNET_break (0);
481 return; 513 GNUNET_SERVICE_client_drop (client);
482 }
483 GNUNET_CONFIGURATION_set_value_number(cfg,
484 "TESTBED",
485 "PEERID",
486 (unsigned long long)peer_id);
487
488 GNUNET_CONFIGURATION_set_value_number(cfg,
489 "PATHS",
490 "PEERID",
491 (unsigned long long)peer_id);
492 peer = GNUNET_new(struct Peer);
493 peer->is_remote = GNUNET_NO;
494 peer->details.local.cfg = cfg;
495 peer->id = peer_id;
496 LOG_DEBUG("Creating peer with id: %u\n",
497 (unsigned int)peer->id);
498 peer->details.local.peer =
499 GNUNET_TESTING_peer_configure(GST_context->system,
500 peer->details.local.cfg, peer->id,
501 NULL /* Peer id */,
502 &emsg);
503 if (NULL == peer->details.local.peer)
504 {
505 LOG(GNUNET_ERROR_TYPE_WARNING,
506 "Configuring peer failed: %s\n",
507 emsg);
508 GNUNET_free(emsg);
509 GNUNET_free(peer);
510 GNUNET_break(0);
511 GNUNET_SERVICE_client_drop(client);
512 return;
513 }
514 peer->details.local.is_running = GNUNET_NO;
515 peer_list_add(peer);
516 env = GNUNET_MQ_msg(reply,
517 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS);
518 reply->peer_id = msg->peer_id;
519 reply->operation_id = msg->operation_id;
520 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client),
521 env);
522 GNUNET_SERVICE_client_continue(client);
523 return; 514 return;
524 } 515 }
516 peer->details.local.is_running = GNUNET_NO;
517 peer_list_add (peer);
518 env = GNUNET_MQ_msg (reply,
519 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS);
520 reply->peer_id = msg->peer_id;
521 reply->operation_id = msg->operation_id;
522 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
523 env);
524 GNUNET_SERVICE_client_continue (client);
525 return;
526 }
525 527
526 /* Forward peer create request */ 528 /* Forward peer create request */
527 route = GST_find_dest_route(host_id); 529 route = GST_find_dest_route (host_id);
528 if (NULL == route) 530 if (NULL == route)
529 { 531 {
530 GNUNET_break(0); 532 GNUNET_break (0);
531 GNUNET_SERVICE_client_continue(client); // ? 533 GNUNET_SERVICE_client_continue (client); // ?
532 return; 534 return;
533 } 535 }
534 peer = GNUNET_new(struct Peer); 536 peer = GNUNET_new (struct Peer);
535 peer->is_remote = GNUNET_YES; 537 peer->is_remote = GNUNET_YES;
536 peer->id = peer_id; 538 peer->id = peer_id;
537 peer->details.remote.slave = GST_slave_list[route->dest]; 539 peer->details.remote.slave = GST_slave_list[route->dest];
538 peer->details.remote.remote_host_id = host_id; 540 peer->details.remote.remote_host_id = host_id;
539 fo_ctxt = GNUNET_new(struct ForwardedOperationContext); 541 fo_ctxt = GNUNET_new (struct ForwardedOperationContext);
540 fo_ctxt->client = client; 542 fo_ctxt->client = client;
541 fo_ctxt->operation_id = GNUNET_ntohll(msg->operation_id); 543 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
542 fo_ctxt->cls = peer; 544 fo_ctxt->cls = peer;
543 fo_ctxt->type = OP_PEER_CREATE; 545 fo_ctxt->type = OP_PEER_CREATE;
544 fo_ctxt->opc = 546 fo_ctxt->opc =
545 GNUNET_TESTBED_forward_operation_msg_(GST_slave_list 547 GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list
546 [route->dest]->controller, 548 [route->dest]->controller,
547 fo_ctxt->operation_id, 549 fo_ctxt->operation_id,
548 &msg->header, 550 &msg->header,
549 &peer_create_success_cb, 551 &peer_create_success_cb,
550 fo_ctxt); 552 fo_ctxt);
551 fo_ctxt->timeout_task = 553 fo_ctxt->timeout_task =
552 GNUNET_SCHEDULER_add_delayed(GST_timeout, 554 GNUNET_SCHEDULER_add_delayed (GST_timeout,
553 &peer_create_forward_timeout, 555 &peer_create_forward_timeout,
554 fo_ctxt); 556 fo_ctxt);
555 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 557 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
556 fopcq_tail, 558 fopcq_tail,
557 fo_ctxt); 559 fo_ctxt);
558 GNUNET_SERVICE_client_continue(client); 560 GNUNET_SERVICE_client_continue (client);
559} 561}
560 562
561 563
@@ -566,63 +568,63 @@ handle_peer_create(void *cls,
566 * @param msg the actual message 568 * @param msg the actual message
567 */ 569 */
568void 570void
569handle_peer_destroy(void *cls, 571handle_peer_destroy (void *cls,
570 const struct GNUNET_TESTBED_PeerDestroyMessage *msg) 572 const struct GNUNET_TESTBED_PeerDestroyMessage *msg)
571{ 573{
572 struct GNUNET_SERVICE_Client *client = cls; 574 struct GNUNET_SERVICE_Client *client = cls;
573 struct ForwardedOperationContext *fopc; 575 struct ForwardedOperationContext *fopc;
574 struct Peer *peer; 576 struct Peer *peer;
575 uint32_t peer_id; 577 uint32_t peer_id;
576 578
577 peer_id = ntohl(msg->peer_id); 579 peer_id = ntohl (msg->peer_id);
578 LOG_DEBUG("Received peer destory on peer: %u and operation id: %llu\n", 580 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %llu\n",
579 (unsigned int)peer_id, 581 (unsigned int) peer_id,
580 (unsigned long long)GNUNET_ntohll(msg->operation_id)); 582 (unsigned long long) GNUNET_ntohll (msg->operation_id));
581 if (!VALID_PEER_ID(peer_id)) 583 if (! VALID_PEER_ID (peer_id))
582 { 584 {
583 LOG(GNUNET_ERROR_TYPE_ERROR, 585 LOG (GNUNET_ERROR_TYPE_ERROR,
584 "Asked to destroy a non existent peer with id: %u\n", peer_id); 586 "Asked to destroy a non existent peer with id: %u\n", peer_id);
585 GST_send_operation_fail_msg(client, 587 GST_send_operation_fail_msg (client,
586 GNUNET_ntohll(msg->operation_id), 588 GNUNET_ntohll (msg->operation_id),
587 "Peer doesn't exist"); 589 "Peer doesn't exist");
588 GNUNET_SERVICE_client_continue(client); 590 GNUNET_SERVICE_client_continue (client);
589 return; 591 return;
590 } 592 }
591 peer = GST_peer_list[peer_id]; 593 peer = GST_peer_list[peer_id];
592 if (GNUNET_YES == peer->is_remote) 594 if (GNUNET_YES == peer->is_remote)
593 { 595 {
594 /* Forward the destory message to sub controller */ 596 /* Forward the destory message to sub controller */
595 fopc = GNUNET_new(struct ForwardedOperationContext); 597 fopc = GNUNET_new (struct ForwardedOperationContext);
596 fopc->client = client; 598 fopc->client = client;
597 fopc->cls = peer; 599 fopc->cls = peer;
598 fopc->type = OP_PEER_DESTROY; 600 fopc->type = OP_PEER_DESTROY;
599 fopc->operation_id = GNUNET_ntohll(msg->operation_id); 601 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
600 fopc->opc = 602 fopc->opc =
601 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 603 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
602 slave->controller, 604 slave->controller,
603 fopc->operation_id, 605 fopc->operation_id,
604 &msg->header, 606 &msg->header,
605 &peer_destroy_success_cb, 607 &peer_destroy_success_cb,
606 fopc); 608 fopc);
607 fopc->timeout_task = 609 fopc->timeout_task =
608 GNUNET_SCHEDULER_add_delayed(GST_timeout, 610 GNUNET_SCHEDULER_add_delayed (GST_timeout,
609 &GST_forwarded_operation_timeout, 611 &GST_forwarded_operation_timeout,
610 fopc); 612 fopc);
611 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 613 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
612 fopcq_tail, 614 fopcq_tail,
613 fopc); 615 fopc);
614 GNUNET_SERVICE_client_continue(client); 616 GNUNET_SERVICE_client_continue (client);
615 return; 617 return;
616 } 618 }
617 peer->destroy_flag = GNUNET_YES; 619 peer->destroy_flag = GNUNET_YES;
618 if (0 == peer->reference_cnt) 620 if (0 == peer->reference_cnt)
619 GST_destroy_peer(peer); 621 GST_destroy_peer (peer);
620 else 622 else
621 LOG(GNUNET_ERROR_TYPE_DEBUG, 623 LOG (GNUNET_ERROR_TYPE_DEBUG,
622 "Delaying peer destroy as peer is currently in use\n"); 624 "Delaying peer destroy as peer is currently in use\n");
623 GST_send_operation_success_msg(client, 625 GST_send_operation_success_msg (client,
624 GNUNET_ntohll(msg->operation_id)); 626 GNUNET_ntohll (msg->operation_id));
625 GNUNET_SERVICE_client_continue(client); 627 GNUNET_SERVICE_client_continue (client);
626} 628}
627 629
628 630
@@ -633,10 +635,10 @@ handle_peer_destroy(void *cls,
633 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 635 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
634 */ 636 */
635static int 637static int
636start_peer(struct Peer *peer) 638start_peer (struct Peer *peer)
637{ 639{
638 GNUNET_assert(GNUNET_NO == peer->is_remote); 640 GNUNET_assert (GNUNET_NO == peer->is_remote);
639 if (GNUNET_OK != GNUNET_TESTING_peer_start(peer->details.local.peer)) 641 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
640 return GNUNET_SYSERR; 642 return GNUNET_SYSERR;
641 peer->details.local.is_running = GNUNET_YES; 643 peer->details.local.is_running = GNUNET_YES;
642 return GNUNET_OK; 644 return GNUNET_OK;
@@ -650,8 +652,8 @@ start_peer(struct Peer *peer)
650 * @param msg the actual message 652 * @param msg the actual message
651 */ 653 */
652void 654void
653handle_peer_start(void *cls, 655handle_peer_start (void *cls,
654 const struct GNUNET_TESTBED_PeerStartMessage *msg) 656 const struct GNUNET_TESTBED_PeerStartMessage *msg)
655{ 657{
656 struct GNUNET_SERVICE_Client *client = cls; 658 struct GNUNET_SERVICE_Client *client = cls;
657 struct GNUNET_MQ_Envelope *env; 659 struct GNUNET_MQ_Envelope *env;
@@ -660,55 +662,56 @@ handle_peer_start(void *cls,
660 struct Peer *peer; 662 struct Peer *peer;
661 uint32_t peer_id; 663 uint32_t peer_id;
662 664
663 peer_id = ntohl(msg->peer_id); 665 peer_id = ntohl (msg->peer_id);
664 if (!VALID_PEER_ID(peer_id)) 666 if (! VALID_PEER_ID (peer_id))
665 { 667 {
666 GNUNET_break(0); 668 GNUNET_break (0);
667 LOG(GNUNET_ERROR_TYPE_ERROR, 669 LOG (GNUNET_ERROR_TYPE_ERROR,
668 "Asked to start a non existent peer with id: %u\n", 670 "Asked to start a non existent peer with id: %u\n",
669 peer_id); 671 peer_id);
670 GNUNET_SERVICE_client_continue(client); 672 GNUNET_SERVICE_client_continue (client);
671 return; 673 return;
672 } 674 }
673 peer = GST_peer_list[peer_id]; 675 peer = GST_peer_list[peer_id];
674 if (GNUNET_YES == peer->is_remote) 676 if (GNUNET_YES == peer->is_remote)
675 { 677 {
676 fopc = GNUNET_new(struct ForwardedOperationContext); 678 fopc = GNUNET_new (struct ForwardedOperationContext);
677 fopc->client = client; 679 fopc->client = client;
678 fopc->operation_id = GNUNET_ntohll(msg->operation_id); 680 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
679 fopc->type = OP_PEER_START; 681 fopc->type = OP_PEER_START;
680 fopc->opc = 682 fopc->opc =
681 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 683 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
682 slave->controller, 684 slave->controller,
683 fopc->operation_id, &msg->header, 685 fopc->operation_id, &msg->header,
684 &GST_forwarded_operation_reply_relay, 686 &
685 fopc); 687 GST_forwarded_operation_reply_relay,
686 fopc->timeout_task = 688 fopc);
687 GNUNET_SCHEDULER_add_delayed(GST_timeout, 689 fopc->timeout_task =
688 &GST_forwarded_operation_timeout, 690 GNUNET_SCHEDULER_add_delayed (GST_timeout,
689 fopc); 691 &GST_forwarded_operation_timeout,
690 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 692 fopc);
691 fopcq_tail, 693 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
692 fopc); 694 fopcq_tail,
693 GNUNET_SERVICE_client_continue(client); 695 fopc);
694 return; 696 GNUNET_SERVICE_client_continue (client);
695 } 697 return;
696 if (GNUNET_OK != start_peer(peer)) 698 }
697 { 699 if (GNUNET_OK != start_peer (peer))
698 GST_send_operation_fail_msg(client, GNUNET_ntohll(msg->operation_id), 700 {
699 "Failed to start"); 701 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
700 GNUNET_SERVICE_client_continue(client); 702 "Failed to start");
701 return; 703 GNUNET_SERVICE_client_continue (client);
702 } 704 return;
703 env = GNUNET_MQ_msg(reply, 705 }
704 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); 706 env = GNUNET_MQ_msg (reply,
705 reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_START); 707 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
706 reply->host_id = htonl(GST_context->host_id); 708 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
709 reply->host_id = htonl (GST_context->host_id);
707 reply->peer_id = msg->peer_id; 710 reply->peer_id = msg->peer_id;
708 reply->operation_id = msg->operation_id; 711 reply->operation_id = msg->operation_id;
709 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 712 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
710 env); 713 env);
711 GNUNET_SERVICE_client_continue(client); 714 GNUNET_SERVICE_client_continue (client);
712} 715}
713 716
714 717
@@ -719,8 +722,8 @@ handle_peer_start(void *cls,
719 * @param msg the actual message 722 * @param msg the actual message
720 */ 723 */
721void 724void
722handle_peer_stop(void *cls, 725handle_peer_stop (void *cls,
723 const struct GNUNET_TESTBED_PeerStopMessage *msg) 726 const struct GNUNET_TESTBED_PeerStopMessage *msg)
724{ 727{
725 struct GNUNET_SERVICE_Client *client = cls; 728 struct GNUNET_SERVICE_Client *client = cls;
726 struct GNUNET_MQ_Envelope *env; 729 struct GNUNET_MQ_Envelope *env;
@@ -729,69 +732,70 @@ handle_peer_stop(void *cls,
729 struct Peer *peer; 732 struct Peer *peer;
730 uint32_t peer_id; 733 uint32_t peer_id;
731 734
732 peer_id = ntohl(msg->peer_id); 735 peer_id = ntohl (msg->peer_id);
733 LOG(GNUNET_ERROR_TYPE_DEBUG, 736 LOG (GNUNET_ERROR_TYPE_DEBUG,
734 "Received PEER_STOP for peer %u\n", 737 "Received PEER_STOP for peer %u\n",
735 (unsigned int)peer_id); 738 (unsigned int) peer_id);
736 if (!VALID_PEER_ID(peer_id)) 739 if (! VALID_PEER_ID (peer_id))
737 { 740 {
738 GST_send_operation_fail_msg(client, 741 GST_send_operation_fail_msg (client,
739 GNUNET_ntohll(msg->operation_id), 742 GNUNET_ntohll (msg->operation_id),
740 "Peer not found"); 743 "Peer not found");
741 GNUNET_SERVICE_client_continue(client); 744 GNUNET_SERVICE_client_continue (client);
742 return; 745 return;
743 } 746 }
744 peer = GST_peer_list[peer_id]; 747 peer = GST_peer_list[peer_id];
745 if (GNUNET_YES == peer->is_remote) 748 if (GNUNET_YES == peer->is_remote)
746 { 749 {
747 LOG(GNUNET_ERROR_TYPE_DEBUG, 750 LOG (GNUNET_ERROR_TYPE_DEBUG,
748 "Forwarding PEER_STOP for peer %u\n", 751 "Forwarding PEER_STOP for peer %u\n",
749 (unsigned int)peer_id); 752 (unsigned int) peer_id);
750 fopc = GNUNET_new(struct ForwardedOperationContext); 753 fopc = GNUNET_new (struct ForwardedOperationContext);
751 fopc->client = client; 754 fopc->client = client;
752 fopc->operation_id = GNUNET_ntohll(msg->operation_id); 755 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
753 fopc->type = OP_PEER_STOP; 756 fopc->type = OP_PEER_STOP;
754 fopc->opc = 757 fopc->opc =
755 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 758 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
756 slave->controller, 759 slave->controller,
757 fopc->operation_id, 760 fopc->operation_id,
758 &msg->header, 761 &msg->header,
759 &GST_forwarded_operation_reply_relay, 762 &
760 fopc); 763 GST_forwarded_operation_reply_relay,
761 fopc->timeout_task = 764 fopc);
762 GNUNET_SCHEDULER_add_delayed(GST_timeout, 765 fopc->timeout_task =
763 &GST_forwarded_operation_timeout, 766 GNUNET_SCHEDULER_add_delayed (GST_timeout,
764 fopc); 767 &GST_forwarded_operation_timeout,
765 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 768 fopc);
766 fopcq_tail, 769 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
767 fopc); 770 fopcq_tail,
768 GNUNET_SERVICE_client_continue(client); 771 fopc);
769 return; 772 GNUNET_SERVICE_client_continue (client);
770 } 773 return;
771 if (GNUNET_OK != stop_peer(peer)) 774 }
772 { 775 if (GNUNET_OK != stop_peer (peer))
773 LOG(GNUNET_ERROR_TYPE_WARNING, 776 {
774 "Stopping peer %u failed\n", 777 LOG (GNUNET_ERROR_TYPE_WARNING,
775 (unsigned int)peer_id); 778 "Stopping peer %u failed\n",
776 GST_send_operation_fail_msg(client, 779 (unsigned int) peer_id);
777 GNUNET_ntohll(msg->operation_id), 780 GST_send_operation_fail_msg (client,
778 "Peer not running"); 781 GNUNET_ntohll (msg->operation_id),
779 GNUNET_SERVICE_client_continue(client); 782 "Peer not running");
780 return; 783 GNUNET_SERVICE_client_continue (client);
781 } 784 return;
782 LOG(GNUNET_ERROR_TYPE_DEBUG, 785 }
783 "Peer %u successfully stopped\n", 786 LOG (GNUNET_ERROR_TYPE_DEBUG,
784 (unsigned int)peer_id); 787 "Peer %u successfully stopped\n",
785 env = GNUNET_MQ_msg(reply, 788 (unsigned int) peer_id);
786 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); 789 env = GNUNET_MQ_msg (reply,
787 reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_STOP); 790 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
788 reply->host_id = htonl(GST_context->host_id); 791 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
792 reply->host_id = htonl (GST_context->host_id);
789 reply->peer_id = msg->peer_id; 793 reply->peer_id = msg->peer_id;
790 reply->operation_id = msg->operation_id; 794 reply->operation_id = msg->operation_id;
791 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 795 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
792 env); 796 env);
793 GNUNET_SERVICE_client_continue(client); 797 GNUNET_SERVICE_client_continue (client);
794 GNUNET_TESTING_peer_wait(peer->details.local.peer); 798 GNUNET_TESTING_peer_wait (peer->details.local.peer);
795} 799}
796 800
797 801
@@ -802,8 +806,9 @@ handle_peer_stop(void *cls,
802 * @param msg the actual message 806 * @param msg the actual message
803 */ 807 */
804void 808void
805handle_peer_get_config(void *cls, 809handle_peer_get_config (void *cls,
806 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) 810 const struct
811 GNUNET_TESTBED_PeerGetConfigurationMessage *msg)
807{ 812{
808 struct GNUNET_SERVICE_Client *client = cls; 813 struct GNUNET_SERVICE_Client *client = cls;
809 struct GNUNET_MQ_Envelope *env; 814 struct GNUNET_MQ_Envelope *env;
@@ -816,67 +821,68 @@ handle_peer_get_config(void *cls,
816 size_t xc_size; 821 size_t xc_size;
817 uint32_t peer_id; 822 uint32_t peer_id;
818 823
819 peer_id = ntohl(msg->peer_id); 824 peer_id = ntohl (msg->peer_id);
820 LOG_DEBUG("Received GET_CONFIG for peer %u\n", 825 LOG_DEBUG ("Received GET_CONFIG for peer %u\n",
821 (unsigned int)peer_id); 826 (unsigned int) peer_id);
822 if (!VALID_PEER_ID(peer_id)) 827 if (! VALID_PEER_ID (peer_id))
823 { 828 {
824 GST_send_operation_fail_msg(client, 829 GST_send_operation_fail_msg (client,
825 GNUNET_ntohll(msg->operation_id), 830 GNUNET_ntohll (msg->operation_id),
826 "Peer not found"); 831 "Peer not found");
827 GNUNET_SERVICE_client_continue(client); 832 GNUNET_SERVICE_client_continue (client);
828 return; 833 return;
829 } 834 }
830 peer = GST_peer_list[peer_id]; 835 peer = GST_peer_list[peer_id];
831 if (GNUNET_YES == peer->is_remote) 836 if (GNUNET_YES == peer->is_remote)
832 { 837 {
833 LOG_DEBUG("Forwarding PEER_GET_CONFIG for peer: %u\n", 838 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n",
834 (unsigned int)peer_id); 839 (unsigned int) peer_id);
835 fopc = GNUNET_new(struct ForwardedOperationContext); 840 fopc = GNUNET_new (struct ForwardedOperationContext);
836 fopc->client = client; 841 fopc->client = client;
837 fopc->operation_id = GNUNET_ntohll(msg->operation_id); 842 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
838 fopc->type = OP_PEER_INFO; 843 fopc->type = OP_PEER_INFO;
839 fopc->opc = 844 fopc->opc =
840 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 845 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
841 slave->controller, 846 slave->controller,
842 fopc->operation_id, 847 fopc->operation_id,
843 &msg->header, 848 &msg->header,
844 &GST_forwarded_operation_reply_relay, 849 &
845 fopc); 850 GST_forwarded_operation_reply_relay,
846 fopc->timeout_task = 851 fopc);
847 GNUNET_SCHEDULER_add_delayed(GST_timeout, 852 fopc->timeout_task =
848 &GST_forwarded_operation_timeout, 853 GNUNET_SCHEDULER_add_delayed (GST_timeout,
849 fopc); 854 &GST_forwarded_operation_timeout,
850 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 855 fopc);
851 fopcq_tail, 856 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
852 fopc); 857 fopcq_tail,
853 GNUNET_SERVICE_client_continue(client); 858 fopc);
854 return; 859 GNUNET_SERVICE_client_continue (client);
855 } 860 return;
856 LOG_DEBUG("Received PEER_GET_CONFIG for peer: %u\n", 861 }
857 peer_id); 862 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n",
863 peer_id);
858 config = 864 config =
859 GNUNET_CONFIGURATION_serialize(GST_peer_list[peer_id]->details.local.cfg, 865 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg,
860 &c_size); 866 &c_size);
861 xc_size = GNUNET_TESTBED_compress_config_(config, 867 xc_size = GNUNET_TESTBED_compress_config_ (config,
862 c_size, 868 c_size,
863 &xconfig); 869 &xconfig);
864 GNUNET_free(config); 870 GNUNET_free (config);
865 env = GNUNET_MQ_msg_extra(reply, 871 env = GNUNET_MQ_msg_extra (reply,
866 xc_size, 872 xc_size,
867 GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); 873 GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION);
868 reply->peer_id = msg->peer_id; 874 reply->peer_id = msg->peer_id;
869 reply->operation_id = msg->operation_id; 875 reply->operation_id = msg->operation_id;
870 GNUNET_TESTING_peer_get_identity(GST_peer_list[peer_id]->details.local.peer, 876 GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer,
871 &reply->peer_identity); 877 &reply->peer_identity);
872 reply->config_size = htons((uint16_t)c_size); 878 reply->config_size = htons ((uint16_t) c_size);
873 GNUNET_memcpy(&reply[1], 879 GNUNET_memcpy (&reply[1],
874 xconfig, 880 xconfig,
875 xc_size); 881 xc_size);
876 GNUNET_free(xconfig); 882 GNUNET_free (xconfig);
877 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 883 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
878 env); 884 env);
879 GNUNET_SERVICE_client_continue(client); 885 GNUNET_SERVICE_client_continue (client);
880} 886}
881 887
882 888
@@ -884,10 +890,10 @@ handle_peer_get_config(void *cls,
884 * Cleans up the Peer reconfigure context list 890 * Cleans up the Peer reconfigure context list
885 */ 891 */
886void 892void
887GST_free_prcq() 893GST_free_prcq ()
888{ 894{
889 while (NULL != prc_head) 895 while (NULL != prc_head)
890 cleanup_prc(prc_head); 896 cleanup_prc (prc_head);
891} 897}
892 898
893 899
@@ -899,21 +905,21 @@ GST_free_prcq()
899 * @return error message (freshly allocated); NULL upon success 905 * @return error message (freshly allocated); NULL upon success
900 */ 906 */
901static char * 907static char *
902update_peer_config(struct Peer *peer, 908update_peer_config (struct Peer *peer,
903 struct GNUNET_CONFIGURATION_Handle *cfg) 909 struct GNUNET_CONFIGURATION_Handle *cfg)
904{ 910{
905 char *emsg; 911 char *emsg;
906 912
907 GNUNET_TESTING_peer_destroy(peer->details.local.peer); 913 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
908 GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); 914 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
909 peer->details.local.cfg = cfg; 915 peer->details.local.cfg = cfg;
910 emsg = NULL; 916 emsg = NULL;
911 peer->details.local.peer 917 peer->details.local.peer
912 = GNUNET_TESTING_peer_configure(GST_context->system, 918 = GNUNET_TESTING_peer_configure (GST_context->system,
913 peer->details.local.cfg, 919 peer->details.local.cfg,
914 peer->id, 920 peer->id,
915 NULL /* Peer id */, 921 NULL /* Peer id */,
916 &emsg); 922 &emsg);
917 return emsg; 923 return emsg;
918} 924}
919 925
@@ -927,39 +933,39 @@ update_peer_config(struct Peer *peer,
927 * error 933 * error
928 */ 934 */
929static void 935static void
930prc_stop_cb(void *cls, 936prc_stop_cb (void *cls,
931 struct GNUNET_TESTING_Peer *p, 937 struct GNUNET_TESTING_Peer *p,
932 int success) 938 int success)
933{ 939{
934 struct PeerReconfigureContext *prc = cls; 940 struct PeerReconfigureContext *prc = cls;
935 struct Peer *peer; 941 struct Peer *peer;
936 char *emsg; 942 char *emsg;
937 943
938 GNUNET_assert(VALID_PEER_ID(prc->peer_id)); 944 GNUNET_assert (VALID_PEER_ID (prc->peer_id));
939 peer = GST_peer_list [prc->peer_id]; 945 peer = GST_peer_list [prc->peer_id];
940 GNUNET_assert(GNUNET_NO == peer->is_remote); 946 GNUNET_assert (GNUNET_NO == peer->is_remote);
941 emsg = update_peer_config(peer, prc->cfg); 947 emsg = update_peer_config (peer, prc->cfg);
942 prc->cfg = NULL; 948 prc->cfg = NULL;
943 prc->stopped = 1; 949 prc->stopped = 1;
944 if (NULL != emsg) 950 if (NULL != emsg)
945 { 951 {
946 GST_send_operation_fail_msg(prc->client, 952 GST_send_operation_fail_msg (prc->client,
947 prc->op_id, 953 prc->op_id,
948 emsg); 954 emsg);
949 goto cleanup; 955 goto cleanup;
950 } 956 }
951 if (GNUNET_OK != start_peer(peer)) 957 if (GNUNET_OK != start_peer (peer))
952 { 958 {
953 GST_send_operation_fail_msg(prc->client, 959 GST_send_operation_fail_msg (prc->client,
954 prc->op_id, 960 prc->op_id,
955 "Failed to start reconfigured peer"); 961 "Failed to start reconfigured peer");
956 goto cleanup; 962 goto cleanup;
957 } 963 }
958 GST_send_operation_success_msg(prc->client, 964 GST_send_operation_success_msg (prc->client,
959 prc->op_id); 965 prc->op_id);
960 966
961cleanup: 967cleanup:
962 cleanup_prc(prc); 968 cleanup_prc (prc);
963 return; 969 return;
964} 970}
965 971
@@ -972,8 +978,8 @@ cleanup:
972 * @return #GNUNET_OK if @a msg is well-formed 978 * @return #GNUNET_OK if @a msg is well-formed
973 */ 979 */
974int 980int
975check_peer_reconfigure(void *cls, 981check_peer_reconfigure (void *cls,
976 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) 982 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg)
977{ 983{
978 return GNUNET_OK; /* checked later */ 984 return GNUNET_OK; /* checked later */
979} 985}
@@ -988,8 +994,9 @@ check_peer_reconfigure(void *cls,
988 * @param msg the actual message 994 * @param msg the actual message
989 */ 995 */
990void 996void
991handle_peer_reconfigure(void *cls, 997handle_peer_reconfigure (void *cls,
992 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) 998 const struct
999 GNUNET_TESTBED_PeerReconfigureMessage *msg)
993{ 1000{
994 struct GNUNET_SERVICE_Client *client = cls; 1001 struct GNUNET_SERVICE_Client *client = cls;
995 struct Peer *peer; 1002 struct Peer *peer;
@@ -1000,114 +1007,115 @@ handle_peer_reconfigure(void *cls,
1000 uint64_t op_id; 1007 uint64_t op_id;
1001 uint32_t peer_id; 1008 uint32_t peer_id;
1002 1009
1003 peer_id = ntohl(msg->peer_id); 1010 peer_id = ntohl (msg->peer_id);
1004 op_id = GNUNET_ntohll(msg->operation_id); 1011 op_id = GNUNET_ntohll (msg->operation_id);
1005 if (!VALID_PEER_ID(peer_id)) 1012 if (! VALID_PEER_ID (peer_id))
1006 { 1013 {
1007 GNUNET_break(0); 1014 GNUNET_break (0);
1008 GST_send_operation_fail_msg(client, 1015 GST_send_operation_fail_msg (client,
1009 op_id, 1016 op_id,
1010 "Peer not found"); 1017 "Peer not found");
1011 GNUNET_SERVICE_client_continue(client); 1018 GNUNET_SERVICE_client_continue (client);
1012 return; 1019 return;
1013 } 1020 }
1014 peer = GST_peer_list[peer_id]; 1021 peer = GST_peer_list[peer_id];
1015 if (GNUNET_YES == peer->is_remote) 1022 if (GNUNET_YES == peer->is_remote)
1016 { 1023 {
1017 LOG_DEBUG("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); 1024 LOG_DEBUG ("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id);
1018 fopc = GNUNET_new(struct ForwardedOperationContext); 1025 fopc = GNUNET_new (struct ForwardedOperationContext);
1019 fopc->client = client; 1026 fopc->client = client;
1020 fopc->operation_id = op_id; 1027 fopc->operation_id = op_id;
1021 fopc->type = OP_PEER_RECONFIGURE; 1028 fopc->type = OP_PEER_RECONFIGURE;
1022 fopc->opc = 1029 fopc->opc =
1023 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 1030 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1024 slave->controller, 1031 slave->controller,
1025 fopc->operation_id, 1032 fopc->operation_id,
1026 &msg->header, 1033 &msg->header,
1027 &GST_forwarded_operation_reply_relay, 1034 &
1028 fopc); 1035 GST_forwarded_operation_reply_relay,
1029 fopc->timeout_task = 1036 fopc);
1030 GNUNET_SCHEDULER_add_delayed(GST_timeout, 1037 fopc->timeout_task =
1031 &GST_forwarded_operation_timeout, 1038 GNUNET_SCHEDULER_add_delayed (GST_timeout,
1032 fopc); 1039 &GST_forwarded_operation_timeout,
1033 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 1040 fopc);
1034 fopcq_tail, 1041 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1035 fopc); 1042 fopcq_tail,
1036 GNUNET_SERVICE_client_continue(client); 1043 fopc);
1037 return; 1044 GNUNET_SERVICE_client_continue (client);
1038 } 1045 return;
1039 LOG_DEBUG("Received PEER_RECONFIGURE for peer %u\n", 1046 }
1040 (unsigned int)peer_id); 1047 LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n",
1048 (unsigned int) peer_id);
1041 if (0 < peer->reference_cnt) 1049 if (0 < peer->reference_cnt)
1042 { 1050 {
1043 GNUNET_break(0); 1051 GNUNET_break (0);
1044 GST_send_operation_fail_msg(client, 1052 GST_send_operation_fail_msg (client,
1045 op_id, 1053 op_id,
1046 "Peer in use"); 1054 "Peer in use");
1047 GNUNET_SERVICE_client_continue(client); 1055 GNUNET_SERVICE_client_continue (client);
1048 return; 1056 return;
1049 } 1057 }
1050 if (GNUNET_YES == peer->destroy_flag) 1058 if (GNUNET_YES == peer->destroy_flag)
1051 { 1059 {
1052 GNUNET_break(0); 1060 GNUNET_break (0);
1053 GST_send_operation_fail_msg(client, 1061 GST_send_operation_fail_msg (client,
1054 op_id, 1062 op_id,
1055 "Peer is being destroyed"); 1063 "Peer is being destroyed");
1056 GNUNET_SERVICE_client_continue(client); 1064 GNUNET_SERVICE_client_continue (client);
1057 return; 1065 return;
1058 } 1066 }
1059 cfg = GNUNET_TESTBED_extract_config_(&msg->header); 1067 cfg = GNUNET_TESTBED_extract_config_ (&msg->header);
1060 if (NULL == cfg) 1068 if (NULL == cfg)
1061 { 1069 {
1062 GNUNET_break(0); 1070 GNUNET_break (0);
1063 GST_send_operation_fail_msg(client, 1071 GST_send_operation_fail_msg (client,
1064 op_id, 1072 op_id,
1065 "Compression error"); 1073 "Compression error");
1066 GNUNET_SERVICE_client_continue(client); 1074 GNUNET_SERVICE_client_continue (client);
1067 return; 1075 return;
1068 } 1076 }
1069 if (GNUNET_NO == peer->details.local.is_running) 1077 if (GNUNET_NO == peer->details.local.is_running)
1070 { 1078 {
1071 emsg = update_peer_config(peer, 1079 emsg = update_peer_config (peer,
1072 cfg); 1080 cfg);
1073 if (NULL != emsg) 1081 if (NULL != emsg)
1074 GST_send_operation_fail_msg(client, 1082 GST_send_operation_fail_msg (client,
1075 op_id, 1083 op_id,
1076 emsg); 1084 emsg);
1077 GST_send_operation_success_msg(client, 1085 GST_send_operation_success_msg (client,
1078 op_id); 1086 op_id);
1079 GNUNET_SERVICE_client_continue(client); 1087 GNUNET_SERVICE_client_continue (client);
1080 GNUNET_free_non_null(emsg); 1088 GNUNET_free_non_null (emsg);
1081 return; 1089 return;
1082 } 1090 }
1083 prc = GNUNET_new(struct PeerReconfigureContext); 1091 prc = GNUNET_new (struct PeerReconfigureContext);
1084 if (GNUNET_OK != 1092 if (GNUNET_OK !=
1085 GNUNET_TESTING_peer_stop_async(peer->details.local.peer, 1093 GNUNET_TESTING_peer_stop_async (peer->details.local.peer,
1086 &prc_stop_cb, 1094 &prc_stop_cb,
1087 prc)) 1095 prc))
1088 { 1096 {
1089 GNUNET_assert(0 < GNUNET_asprintf(&emsg, 1097 GNUNET_assert (0 < GNUNET_asprintf (&emsg,
1090 "Error trying to stop peer %u asynchronously\n", 1098 "Error trying to stop peer %u asynchronously\n",
1091 peer_id)); 1099 peer_id));
1092 LOG(GNUNET_ERROR_TYPE_ERROR, 1100 LOG (GNUNET_ERROR_TYPE_ERROR,
1093 "%s\n", 1101 "%s\n",
1094 emsg); 1102 emsg);
1095 GST_send_operation_fail_msg(client, 1103 GST_send_operation_fail_msg (client,
1096 op_id, 1104 op_id,
1097 emsg); 1105 emsg);
1098 GNUNET_SERVICE_client_continue(client); 1106 GNUNET_SERVICE_client_continue (client);
1099 GNUNET_free(prc); 1107 GNUNET_free (prc);
1100 GNUNET_free(emsg); 1108 GNUNET_free (emsg);
1101 return; 1109 return;
1102 } 1110 }
1103 prc->cfg = cfg; 1111 prc->cfg = cfg;
1104 prc->peer_id = peer_id; 1112 prc->peer_id = peer_id;
1105 prc->op_id = op_id; 1113 prc->op_id = op_id;
1106 prc->client = client; 1114 prc->client = client;
1107 GNUNET_CONTAINER_DLL_insert_tail(prc_head, 1115 GNUNET_CONTAINER_DLL_insert_tail (prc_head,
1108 prc_tail, 1116 prc_tail,
1109 prc); 1117 prc);
1110 GNUNET_SERVICE_client_continue(client); 1118 GNUNET_SERVICE_client_continue (client);
1111} 1119}
1112 1120
1113 1121
@@ -1115,10 +1123,10 @@ handle_peer_reconfigure(void *cls,
1115 * Frees the ManageServiceContext queue 1123 * Frees the ManageServiceContext queue
1116 */ 1124 */
1117void 1125void
1118GST_free_mctxq() 1126GST_free_mctxq ()
1119{ 1127{
1120 while (NULL != mctx_head) 1128 while (NULL != mctx_head)
1121 cleanup_mctx(mctx_head); 1129 cleanup_mctx (mctx_head);
1122} 1130}
1123 1131
1124 1132
@@ -1129,17 +1137,17 @@ GST_free_mctxq()
1129 * @return a string interpretation of the request status 1137 * @return a string interpretation of the request status
1130 */ 1138 */
1131static const char * 1139static const char *
1132arm_req_string(enum GNUNET_ARM_RequestStatus rs) 1140arm_req_string (enum GNUNET_ARM_RequestStatus rs)
1133{ 1141{
1134 switch (rs) 1142 switch (rs)
1135 { 1143 {
1136 case GNUNET_ARM_REQUEST_SENT_OK: 1144 case GNUNET_ARM_REQUEST_SENT_OK:
1137 return _("Message was sent successfully"); 1145 return _ ("Message was sent successfully");
1138 1146
1139 case GNUNET_ARM_REQUEST_DISCONNECTED: 1147 case GNUNET_ARM_REQUEST_DISCONNECTED:
1140 return _("We disconnected from ARM before we could send a request"); 1148 return _ ("We disconnected from ARM before we could send a request");
1141 } 1149 }
1142 return _("Unknown request status"); 1150 return _ ("Unknown request status");
1143} 1151}
1144 1152
1145 1153
@@ -1150,41 +1158,41 @@ arm_req_string(enum GNUNET_ARM_RequestStatus rs)
1150 * @return a string interpretation 1158 * @return a string interpretation
1151 */ 1159 */
1152static const char * 1160static const char *
1153arm_ret_string(enum GNUNET_ARM_Result result) 1161arm_ret_string (enum GNUNET_ARM_Result result)
1154{ 1162{
1155 switch (result) 1163 switch (result)
1156 { 1164 {
1157 case GNUNET_ARM_RESULT_STOPPED: 1165 case GNUNET_ARM_RESULT_STOPPED:
1158 return _("%s is stopped"); 1166 return _ ("%s is stopped");
1159 1167
1160 case GNUNET_ARM_RESULT_STARTING: 1168 case GNUNET_ARM_RESULT_STARTING:
1161 return _("%s is starting"); 1169 return _ ("%s is starting");
1162 1170
1163 case GNUNET_ARM_RESULT_STOPPING: 1171 case GNUNET_ARM_RESULT_STOPPING:
1164 return _("%s is stopping"); 1172 return _ ("%s is stopping");
1165 1173
1166 case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: 1174 case GNUNET_ARM_RESULT_IS_STARTING_ALREADY:
1167 return _("%s is starting already"); 1175 return _ ("%s is starting already");
1168 1176
1169 case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: 1177 case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY:
1170 return _("%s is stopping already"); 1178 return _ ("%s is stopping already");
1171 1179
1172 case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: 1180 case GNUNET_ARM_RESULT_IS_STARTED_ALREADY:
1173 return _("%s is started already"); 1181 return _ ("%s is started already");
1174 1182
1175 case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: 1183 case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY:
1176 return _("%s is stopped already"); 1184 return _ ("%s is stopped already");
1177 1185
1178 case GNUNET_ARM_RESULT_IS_NOT_KNOWN: 1186 case GNUNET_ARM_RESULT_IS_NOT_KNOWN:
1179 return _("%s service is not known to ARM"); 1187 return _ ("%s service is not known to ARM");
1180 1188
1181 case GNUNET_ARM_RESULT_START_FAILED: 1189 case GNUNET_ARM_RESULT_START_FAILED:
1182 return _("%s service failed to start"); 1190 return _ ("%s service failed to start");
1183 1191
1184 case GNUNET_ARM_RESULT_IN_SHUTDOWN: 1192 case GNUNET_ARM_RESULT_IN_SHUTDOWN:
1185 return _("%s service can't be started because ARM is shutting down"); 1193 return _ ("%s service can't be started because ARM is shutting down");
1186 } 1194 }
1187 return _("%.s Unknown result code."); 1195 return _ ("%.s Unknown result code.");
1188} 1196}
1189 1197
1190 1198
@@ -1199,9 +1207,9 @@ arm_ret_string(enum GNUNET_ARM_Result result)
1199 * @param result result of the operation 1207 * @param result result of the operation
1200 */ 1208 */
1201static void 1209static void
1202service_manage_result_cb(void *cls, 1210service_manage_result_cb (void *cls,
1203 enum GNUNET_ARM_RequestStatus rs, 1211 enum GNUNET_ARM_RequestStatus rs,
1204 enum GNUNET_ARM_Result result) 1212 enum GNUNET_ARM_Result result)
1205{ 1213{
1206 struct ManageServiceContext *mctx = cls; 1214 struct ManageServiceContext *mctx = cls;
1207 char *emsg; 1215 char *emsg;
@@ -1210,55 +1218,55 @@ service_manage_result_cb(void *cls,
1210 if (GNUNET_YES == mctx->expired) 1218 if (GNUNET_YES == mctx->expired)
1211 return; 1219 return;
1212 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 1220 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
1213 { 1221 {
1214 GNUNET_asprintf(&emsg, 1222 GNUNET_asprintf (&emsg,
1215 "Error communicating with Peer %u's ARM: %s", 1223 "Error communicating with Peer %u's ARM: %s",
1216 mctx->peer->id, 1224 mctx->peer->id,
1217 arm_req_string(rs)); 1225 arm_req_string (rs));
1218 goto ret; 1226 goto ret;
1219 } 1227 }
1220 if (1 == mctx->start) 1228 if (1 == mctx->start)
1221 goto service_start_check; 1229 goto service_start_check;
1222 if (!((GNUNET_ARM_RESULT_STOPPED == result) 1230 if (! ((GNUNET_ARM_RESULT_STOPPED == result)
1223 || (GNUNET_ARM_RESULT_STOPPING == result) 1231 || (GNUNET_ARM_RESULT_STOPPING == result)
1224 || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result) 1232 || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result)
1225 || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result))) 1233 || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)))
1226 { 1234 {
1227 /* stopping a service failed */ 1235 /* stopping a service failed */
1228 GNUNET_asprintf(&emsg, 1236 GNUNET_asprintf (&emsg,
1229 arm_ret_string(result), 1237 arm_ret_string (result),
1230 mctx->service); 1238 mctx->service);
1231 goto ret; 1239 goto ret;
1232 } 1240 }
1233 /* service stopped successfully */ 1241 /* service stopped successfully */
1234 goto ret; 1242 goto ret;
1235 1243
1236service_start_check: 1244service_start_check:
1237 if (!((GNUNET_ARM_RESULT_STARTING == result) 1245 if (! ((GNUNET_ARM_RESULT_STARTING == result)
1238 || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result) 1246 || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result)
1239 || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result))) 1247 || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)))
1240 { 1248 {
1241 /* starting a service failed */ 1249 /* starting a service failed */
1242 GNUNET_asprintf(&emsg, 1250 GNUNET_asprintf (&emsg,
1243 arm_ret_string(result), 1251 arm_ret_string (result),
1244 mctx->service); 1252 mctx->service);
1245 goto ret; 1253 goto ret;
1246 } 1254 }
1247 /* service started successfully */ 1255 /* service started successfully */
1248 1256
1249ret: 1257ret:
1250 if (NULL != emsg) 1258 if (NULL != emsg)
1251 { 1259 {
1252 LOG_DEBUG("%s\n", emsg); 1260 LOG_DEBUG ("%s\n", emsg);
1253 GST_send_operation_fail_msg(mctx->client, 1261 GST_send_operation_fail_msg (mctx->client,
1254 mctx->op_id, 1262 mctx->op_id,
1255 emsg); 1263 emsg);
1256 } 1264 }
1257 else 1265 else
1258 GST_send_operation_success_msg(mctx->client, 1266 GST_send_operation_success_msg (mctx->client,
1259 mctx->op_id); 1267 mctx->op_id);
1260 GNUNET_free_non_null(emsg); 1268 GNUNET_free_non_null (emsg);
1261 cleanup_mctx(mctx); 1269 cleanup_mctx (mctx);
1262} 1270}
1263 1271
1264 1272
@@ -1270,25 +1278,26 @@ ret:
1270 * @return #GNUNET_OK if @a msg is well-formed 1278 * @return #GNUNET_OK if @a msg is well-formed
1271 */ 1279 */
1272int 1280int
1273check_manage_peer_service(void *cls, 1281check_manage_peer_service (void *cls,
1274 const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) 1282 const struct
1283 GNUNET_TESTBED_ManagePeerServiceMessage *msg)
1275{ 1284{
1276 uint16_t msize; 1285 uint16_t msize;
1277 const char* service; 1286 const char*service;
1278 1287
1279 msize = ntohs(msg->header.size); 1288 msize = ntohs (msg->header.size);
1280 service = (const char *)&msg[1]; 1289 service = (const char *) &msg[1];
1281 if ('\0' != service[msize - sizeof 1290 if ('\0' != service[msize - sizeof
1282 (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) 1291 (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1])
1283 { 1292 {
1284 GNUNET_break_op(0); 1293 GNUNET_break_op (0);
1285 return GNUNET_SYSERR; 1294 return GNUNET_SYSERR;
1286 } 1295 }
1287 if (1 < msg->start) 1296 if (1 < msg->start)
1288 { 1297 {
1289 GNUNET_break_op(0); 1298 GNUNET_break_op (0);
1290 return GNUNET_SYSERR; 1299 return GNUNET_SYSERR;
1291 } 1300 }
1292 return GNUNET_OK; 1301 return GNUNET_OK;
1293} 1302}
1294 1303
@@ -1300,11 +1309,12 @@ check_manage_peer_service(void *cls,
1300 * @param msg the actual message 1309 * @param msg the actual message
1301 */ 1310 */
1302void 1311void
1303handle_manage_peer_service(void *cls, 1312handle_manage_peer_service (void *cls,
1304 const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) 1313 const struct
1314 GNUNET_TESTBED_ManagePeerServiceMessage *msg)
1305{ 1315{
1306 struct GNUNET_SERVICE_Client *client = cls; 1316 struct GNUNET_SERVICE_Client *client = cls;
1307 const char* service; 1317 const char*service;
1308 struct Peer *peer; 1318 struct Peer *peer;
1309 char *emsg; 1319 char *emsg;
1310 struct GNUNET_ARM_Handle *ah; 1320 struct GNUNET_ARM_Handle *ah;
@@ -1313,100 +1323,101 @@ handle_manage_peer_service(void *cls,
1313 uint64_t op_id; 1323 uint64_t op_id;
1314 uint32_t peer_id; 1324 uint32_t peer_id;
1315 1325
1316 service = (const char *)&msg[1]; 1326 service = (const char *) &msg[1];
1317 peer_id = ntohl(msg->peer_id); 1327 peer_id = ntohl (msg->peer_id);
1318 op_id = GNUNET_ntohll(msg->operation_id); 1328 op_id = GNUNET_ntohll (msg->operation_id);
1319 LOG_DEBUG("Received request to manage service %s on peer %u\n", 1329 LOG_DEBUG ("Received request to manage service %s on peer %u\n",
1320 service, (unsigned int)peer_id); 1330 service, (unsigned int) peer_id);
1321 if ((GST_peer_list_size <= peer_id) 1331 if ((GST_peer_list_size <= peer_id)
1322 || (NULL == (peer = GST_peer_list[peer_id]))) 1332 || (NULL == (peer = GST_peer_list[peer_id])))
1323 { 1333 {
1324 GNUNET_asprintf(&emsg, "Asked to manage service of a non existent peer " 1334 GNUNET_asprintf (&emsg, "Asked to manage service of a non existent peer "
1325 "with id: %u", peer_id); 1335 "with id: %u", peer_id);
1326 goto err_ret; 1336 goto err_ret;
1327 } 1337 }
1328 if (0 == strcasecmp("arm", service)) 1338 if (0 == strcasecmp ("arm", service))
1329 { 1339 {
1330 emsg = GNUNET_strdup("Cannot start/stop peer's ARM service. " 1340 emsg = GNUNET_strdup ("Cannot start/stop peer's ARM service. "
1331 "Use peer start/stop for that"); 1341 "Use peer start/stop for that");
1332 goto err_ret; 1342 goto err_ret;
1333 } 1343 }
1334 if (GNUNET_YES == peer->is_remote) 1344 if (GNUNET_YES == peer->is_remote)
1335 { 1345 {
1336 /* Forward the destory message to sub controller */ 1346 /* Forward the destory message to sub controller */
1337 fopc = GNUNET_new(struct ForwardedOperationContext); 1347 fopc = GNUNET_new (struct ForwardedOperationContext);
1338 fopc->client = client; 1348 fopc->client = client;
1339 fopc->cls = peer; 1349 fopc->cls = peer;
1340 fopc->type = OP_MANAGE_SERVICE; 1350 fopc->type = OP_MANAGE_SERVICE;
1341 fopc->operation_id = op_id; 1351 fopc->operation_id = op_id;
1342 fopc->opc = 1352 fopc->opc =
1343 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 1353 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1344 slave->controller, 1354 slave->controller,
1345 fopc->operation_id, 1355 fopc->operation_id,
1346 &msg->header, 1356 &msg->header,
1347 &GST_forwarded_operation_reply_relay, 1357 &
1348 fopc); 1358 GST_forwarded_operation_reply_relay,
1349 fopc->timeout_task = 1359 fopc);
1350 GNUNET_SCHEDULER_add_delayed(GST_timeout, 1360 fopc->timeout_task =
1351 &GST_forwarded_operation_timeout, 1361 GNUNET_SCHEDULER_add_delayed (GST_timeout,
1352 fopc); 1362 &GST_forwarded_operation_timeout,
1353 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 1363 fopc);
1354 fopcq_tail, 1364 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1355 fopc); 1365 fopcq_tail,
1356 GNUNET_SERVICE_client_continue(client); 1366 fopc);
1357 return; 1367 GNUNET_SERVICE_client_continue (client);
1358 } 1368 return;
1369 }
1359 if (GNUNET_NO == peer->details.local.is_running) 1370 if (GNUNET_NO == peer->details.local.is_running)
1360 { 1371 {
1361 emsg = GNUNET_strdup("Peer not running\n"); 1372 emsg = GNUNET_strdup ("Peer not running\n");
1362 goto err_ret; 1373 goto err_ret;
1363 } 1374 }
1364 if ((0 != peer->reference_cnt) 1375 if ((0 != peer->reference_cnt)
1365 && ((0 == strcasecmp("core", service)) 1376 && ((0 == strcasecmp ("core", service))
1366 || (0 == strcasecmp("transport", service)))) 1377 || (0 == strcasecmp ("transport", service))))
1367 { 1378 {
1368 GNUNET_asprintf(&emsg, "Cannot stop %s service of peer with id: %u " 1379 GNUNET_asprintf (&emsg, "Cannot stop %s service of peer with id: %u "
1369 "since it is required by existing operations", 1380 "since it is required by existing operations",
1370 service, peer_id); 1381 service, peer_id);
1371 goto err_ret; 1382 goto err_ret;
1372 } 1383 }
1373 ah = GNUNET_ARM_connect(peer->details.local.cfg, NULL, NULL); 1384 ah = GNUNET_ARM_connect (peer->details.local.cfg, NULL, NULL);
1374 if (NULL == ah) 1385 if (NULL == ah)
1375 { 1386 {
1376 GNUNET_asprintf(&emsg, 1387 GNUNET_asprintf (&emsg,
1377 "Cannot connect to ARM service of peer with id: %u", 1388 "Cannot connect to ARM service of peer with id: %u",
1378 peer_id); 1389 peer_id);
1379 goto err_ret; 1390 goto err_ret;
1380 } 1391 }
1381 mctx = GNUNET_new(struct ManageServiceContext); 1392 mctx = GNUNET_new (struct ManageServiceContext);
1382 mctx->peer = peer; 1393 mctx->peer = peer;
1383 peer->reference_cnt++; 1394 peer->reference_cnt++;
1384 mctx->op_id = op_id; 1395 mctx->op_id = op_id;
1385 mctx->ah = ah; 1396 mctx->ah = ah;
1386 mctx->client = client; 1397 mctx->client = client;
1387 mctx->start = msg->start; 1398 mctx->start = msg->start;
1388 mctx->service = GNUNET_strdup(service); 1399 mctx->service = GNUNET_strdup (service);
1389 GNUNET_CONTAINER_DLL_insert_tail(mctx_head, 1400 GNUNET_CONTAINER_DLL_insert_tail (mctx_head,
1390 mctx_tail, 1401 mctx_tail,
1391 mctx); 1402 mctx);
1392 if (1 == mctx->start) 1403 if (1 == mctx->start)
1393 GNUNET_ARM_request_service_start(mctx->ah, 1404 GNUNET_ARM_request_service_start (mctx->ah,
1394 service, 1405 service,
1395 GNUNET_OS_INHERIT_STD_ERR, 1406 GNUNET_OS_INHERIT_STD_ERR,
1407 &service_manage_result_cb,
1408 mctx);
1409 else
1410 GNUNET_ARM_request_service_stop (mctx->ah, service,
1396 &service_manage_result_cb, 1411 &service_manage_result_cb,
1397 mctx); 1412 mctx);
1398 else 1413 GNUNET_SERVICE_client_continue (client);
1399 GNUNET_ARM_request_service_stop(mctx->ah, service,
1400 &service_manage_result_cb,
1401 mctx);
1402 GNUNET_SERVICE_client_continue(client);
1403 return; 1414 return;
1404 1415
1405err_ret: 1416err_ret:
1406 LOG(GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); 1417 LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
1407 GST_send_operation_fail_msg(client, op_id, emsg); 1418 GST_send_operation_fail_msg (client, op_id, emsg);
1408 GNUNET_free(emsg); 1419 GNUNET_free (emsg);
1409 GNUNET_SERVICE_client_continue(client); 1420 GNUNET_SERVICE_client_continue (client);
1410} 1421}
1411 1422
1412 1423
@@ -1414,7 +1425,7 @@ err_ret:
1414 * Stops and destroys all peers 1425 * Stops and destroys all peers
1415 */ 1426 */
1416void 1427void
1417GST_destroy_peers() 1428GST_destroy_peers ()
1418{ 1429{
1419 struct Peer *peer; 1430 struct Peer *peer;
1420 unsigned int id; 1431 unsigned int id;
@@ -1422,34 +1433,34 @@ GST_destroy_peers()
1422 if (NULL == GST_peer_list) 1433 if (NULL == GST_peer_list)
1423 return; 1434 return;
1424 for (id = 0; id < GST_peer_list_size; id++) 1435 for (id = 0; id < GST_peer_list_size; id++)
1425 { 1436 {
1426 peer = GST_peer_list[id]; 1437 peer = GST_peer_list[id];
1427 if (NULL == peer) 1438 if (NULL == peer)
1428 continue; 1439 continue;
1429 /* If destroy flag is set it means that this peer should have been 1440 /* If destroy flag is set it means that this peer should have been
1430 * destroyed by a context which we destroy before */ 1441 * destroyed by a context which we destroy before */
1431 GNUNET_break(GNUNET_NO == peer->destroy_flag); 1442 GNUNET_break (GNUNET_NO == peer->destroy_flag);
1432 /* counter should be zero as we free all contexts before */ 1443 /* counter should be zero as we free all contexts before */
1433 GNUNET_break(0 == peer->reference_cnt); 1444 GNUNET_break (0 == peer->reference_cnt);
1434 if ((GNUNET_NO == peer->is_remote) && 1445 if ((GNUNET_NO == peer->is_remote) &&
1435 (GNUNET_YES == peer->details.local.is_running)) 1446 (GNUNET_YES == peer->details.local.is_running))
1436 GNUNET_TESTING_peer_kill(peer->details.local.peer); 1447 GNUNET_TESTING_peer_kill (peer->details.local.peer);
1437 } 1448 }
1438 for (id = 0; id < GST_peer_list_size; id++) 1449 for (id = 0; id < GST_peer_list_size; id++)
1450 {
1451 peer = GST_peer_list[id];
1452 if (NULL == peer)
1453 continue;
1454 if (GNUNET_NO == peer->is_remote)
1439 { 1455 {
1440 peer = GST_peer_list[id]; 1456 if (GNUNET_YES == peer->details.local.is_running)
1441 if (NULL == peer) 1457 GNUNET_TESTING_peer_wait (peer->details.local.peer);
1442 continue; 1458 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1443 if (GNUNET_NO == peer->is_remote) 1459 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
1444 {
1445 if (GNUNET_YES == peer->details.local.is_running)
1446 GNUNET_TESTING_peer_wait(peer->details.local.peer);
1447 GNUNET_TESTING_peer_destroy(peer->details.local.peer);
1448 GNUNET_CONFIGURATION_destroy(peer->details.local.cfg);
1449 }
1450 GNUNET_free(peer);
1451 } 1460 }
1452 GNUNET_free_non_null(GST_peer_list); 1461 GNUNET_free (peer);
1462 }
1463 GNUNET_free_non_null (GST_peer_list);
1453 GST_peer_list = NULL; 1464 GST_peer_list = NULL;
1454 GST_peer_list_size = 0; 1465 GST_peer_list_size = 0;
1455} 1466}
@@ -1464,34 +1475,34 @@ GST_destroy_peers()
1464 * @param msg the message to relay 1475 * @param msg the message to relay
1465 */ 1476 */
1466static void 1477static void
1467shutdown_peers_reply_cb(void *cls, 1478shutdown_peers_reply_cb (void *cls,
1468 const struct GNUNET_MessageHeader *msg) 1479 const struct GNUNET_MessageHeader *msg)
1469{ 1480{
1470 struct ForwardedOperationContext *fo_ctxt = cls; 1481 struct ForwardedOperationContext *fo_ctxt = cls;
1471 struct HandlerContext_ShutdownPeers *hc; 1482 struct HandlerContext_ShutdownPeers *hc;
1472 1483
1473 hc = fo_ctxt->cls; 1484 hc = fo_ctxt->cls;
1474 GNUNET_assert(0 < hc->nslaves); 1485 GNUNET_assert (0 < hc->nslaves);
1475 hc->nslaves--; 1486 hc->nslaves--;
1476 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS != 1487 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS !=
1477 ntohs(msg->type)) 1488 ntohs (msg->type))
1478 hc->timeout = GNUNET_YES; 1489 hc->timeout = GNUNET_YES;
1479 if (0 == hc->nslaves) 1490 if (0 == hc->nslaves)
1480 { 1491 {
1481 if (GNUNET_YES == hc->timeout) 1492 if (GNUNET_YES == hc->timeout)
1482 GST_send_operation_fail_msg(fo_ctxt->client, 1493 GST_send_operation_fail_msg (fo_ctxt->client,
1483 fo_ctxt->operation_id, 1494 fo_ctxt->operation_id,
1484 "Timeout at a slave controller"); 1495 "Timeout at a slave controller");
1485 else 1496 else
1486 GST_send_operation_success_msg(fo_ctxt->client, 1497 GST_send_operation_success_msg (fo_ctxt->client,
1487 fo_ctxt->operation_id); 1498 fo_ctxt->operation_id);
1488 GNUNET_free(hc); 1499 GNUNET_free (hc);
1489 hc = NULL; 1500 hc = NULL;
1490 } 1501 }
1491 GNUNET_CONTAINER_DLL_remove(fopcq_head, 1502 GNUNET_CONTAINER_DLL_remove (fopcq_head,
1492 fopcq_tail, 1503 fopcq_tail,
1493 fo_ctxt); 1504 fo_ctxt);
1494 GNUNET_free(fo_ctxt); 1505 GNUNET_free (fo_ctxt);
1495} 1506}
1496 1507
1497 1508
@@ -1502,8 +1513,8 @@ shutdown_peers_reply_cb(void *cls,
1502 * @param msg the actual message 1513 * @param msg the actual message
1503 */ 1514 */
1504void 1515void
1505handle_shutdown_peers(void *cls, 1516handle_shutdown_peers (void *cls,
1506 const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) 1517 const struct GNUNET_TESTBED_ShutdownPeersMessage *msg)
1507{ 1518{
1508 struct GNUNET_SERVICE_Client *client = cls; 1519 struct GNUNET_SERVICE_Client *client = cls;
1509 struct HandlerContext_ShutdownPeers *hc; 1520 struct HandlerContext_ShutdownPeers *hc;
@@ -1512,48 +1523,48 @@ handle_shutdown_peers(void *cls,
1512 uint64_t op_id; 1523 uint64_t op_id;
1513 unsigned int cnt; 1524 unsigned int cnt;
1514 1525
1515 LOG_DEBUG("Received SHUTDOWN_PEERS\n"); 1526 LOG_DEBUG ("Received SHUTDOWN_PEERS\n");
1516 /* Stop and destroy all peers */ 1527 /* Stop and destroy all peers */
1517 GST_free_mctxq(); 1528 GST_free_mctxq ();
1518 GST_free_occq(); 1529 GST_free_occq ();
1519 GST_free_roccq(); 1530 GST_free_roccq ();
1520 GST_clear_fopcq(); 1531 GST_clear_fopcq ();
1521 /* Forward to all slaves which we have started */ 1532 /* Forward to all slaves which we have started */
1522 op_id = GNUNET_ntohll(msg->operation_id); 1533 op_id = GNUNET_ntohll (msg->operation_id);
1523 hc = GNUNET_new(struct HandlerContext_ShutdownPeers); 1534 hc = GNUNET_new (struct HandlerContext_ShutdownPeers);
1524 /* FIXME: have a better implementation where we track which slaves are 1535 /* FIXME: have a better implementation where we track which slaves are
1525 started by this controller */ 1536 started by this controller */
1526 for (cnt = 0; cnt < GST_slave_list_size; cnt++) 1537 for (cnt = 0; cnt < GST_slave_list_size; cnt++)
1527 { 1538 {
1528 slave = GST_slave_list[cnt]; 1539 slave = GST_slave_list[cnt];
1529 if (NULL == slave) 1540 if (NULL == slave)
1530 continue; 1541 continue;
1531 if (NULL == slave->controller_proc) /* We didn't start the slave */ 1542 if (NULL == slave->controller_proc) /* We didn't start the slave */
1532 continue; 1543 continue;
1533 LOG_DEBUG("Forwarding SHUTDOWN_PEERS\n"); 1544 LOG_DEBUG ("Forwarding SHUTDOWN_PEERS\n");
1534 hc->nslaves++; 1545 hc->nslaves++;
1535 fo_ctxt = GNUNET_new(struct ForwardedOperationContext); 1546 fo_ctxt = GNUNET_new (struct ForwardedOperationContext);
1536 fo_ctxt->client = client; 1547 fo_ctxt->client = client;
1537 fo_ctxt->operation_id = op_id; 1548 fo_ctxt->operation_id = op_id;
1538 fo_ctxt->cls = hc; 1549 fo_ctxt->cls = hc;
1539 fo_ctxt->type = OP_SHUTDOWN_PEERS; 1550 fo_ctxt->type = OP_SHUTDOWN_PEERS;
1540 fo_ctxt->opc = 1551 fo_ctxt->opc =
1541 GNUNET_TESTBED_forward_operation_msg_(slave->controller, 1552 GNUNET_TESTBED_forward_operation_msg_ (slave->controller,
1542 fo_ctxt->operation_id, 1553 fo_ctxt->operation_id,
1543 &msg->header, 1554 &msg->header,
1544 shutdown_peers_reply_cb, 1555 shutdown_peers_reply_cb,
1545 fo_ctxt); 1556 fo_ctxt);
1546 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 1557 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1547 fopcq_tail, 1558 fopcq_tail,
1548 fo_ctxt); 1559 fo_ctxt);
1549 } 1560 }
1550 LOG_DEBUG("Shutting down peers\n"); 1561 LOG_DEBUG ("Shutting down peers\n");
1551 GST_destroy_peers(); 1562 GST_destroy_peers ();
1552 if (0 == hc->nslaves) 1563 if (0 == hc->nslaves)
1553 { 1564 {
1554 GST_send_operation_success_msg(client, 1565 GST_send_operation_success_msg (client,
1555 op_id); 1566 op_id);
1556 GNUNET_free(hc); 1567 GNUNET_free (hc);
1557 } 1568 }
1558 GNUNET_SERVICE_client_continue(client); 1569 GNUNET_SERVICE_client_continue (client);
1559} 1570}