aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-08-31 10:36:28 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-08-31 10:36:28 +0000
commita94a1861d123fe850d2ab5ae74cbb59b132a15ea (patch)
treea16d2518067d13f2463e83cd9dc66bdd6b733621 /src/testbed/testbed_api.c
parentd0c55c3ee57913977b1497ea0e6f20573820b206 (diff)
downloadgnunet-a94a1861d123fe850d2ab5ae74cbb59b132a15ea.tar.gz
gnunet-a94a1861d123fe850d2ab5ae74cbb59b132a15ea.zip
adhering to indentation standard
Diffstat (limited to 'src/testbed/testbed_api.c')
-rw-r--r--src/testbed/testbed_api.c573
1 files changed, 298 insertions, 275 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 87a6aa45f..ecc897205 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -81,7 +81,7 @@ struct MessageQueue
81 * next pointer for DLL 81 * next pointer for DLL
82 */ 82 */
83 struct MessageQueue *next; 83 struct MessageQueue *next;
84 84
85 /** 85 /**
86 * prev pointer for DLL 86 * prev pointer for DLL
87 */ 87 */
@@ -160,17 +160,17 @@ struct GNUNET_TESTBED_HostRegistrationHandle
160 */ 160 */
161struct ForwardedOperationData 161struct ForwardedOperationData
162{ 162{
163 163
164 /** 164 /**
165 * The callback to call when reply is available 165 * The callback to call when reply is available
166 */ 166 */
167 GNUNET_CLIENT_MessageHandler cc; 167 GNUNET_CLIENT_MessageHandler cc;
168 168
169 /** 169 /**
170 * The closure for the above callback 170 * The closure for the above callback
171 */ 171 */
172 void *cc_cls; 172 void *cc_cls;
173 173
174}; 174};
175 175
176 176
@@ -215,8 +215,8 @@ handle_addhostconfirm (struct GNUNET_TESTBED_Controller *c,
215 215
216 rh = c->rh; 216 rh = c->rh;
217 if (NULL == rh) 217 if (NULL == rh)
218 { 218 {
219 return GNUNET_OK; 219 return GNUNET_OK;
220 } 220 }
221 if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id)) 221 if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
222 { 222 {
@@ -229,20 +229,20 @@ handle_addhostconfirm (struct GNUNET_TESTBED_Controller *c,
229 if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size) 229 if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size)
230 { 230 {
231 LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id)); 231 LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id));
232 GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c); 232 GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c);
233 rh->cc (rh->cc_cls, NULL); 233 rh->cc (rh->cc_cls, NULL);
234 GNUNET_free (rh); 234 GNUNET_free (rh);
235 return GNUNET_OK; 235 return GNUNET_OK;
236 } 236 }
237 /* We have an error message */ 237 /* We have an error message */
238 emsg = (char *) &msg[1]; 238 emsg = (char *) &msg[1];
239 if ('\0' != emsg[msg_size - 239 if ('\0' !=
240 sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)]) 240 emsg[msg_size - sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)])
241 { 241 {
242 GNUNET_break (0); 242 GNUNET_break (0);
243 GNUNET_free (rh); 243 GNUNET_free (rh);
244 return GNUNET_NO; 244 return GNUNET_NO;
245 } 245 }
246 LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"), 246 LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"),
247 ntohl (msg->host_id), emsg); 247 ntohl (msg->host_id), emsg);
248 rh->cc (rh->cc_cls, emsg); 248 rh->cc (rh->cc_cls, emsg);
@@ -268,7 +268,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
268 struct OperationContext *opc; 268 struct OperationContext *opc;
269 struct GNUNET_TESTBED_EventInformation *event; 269 struct GNUNET_TESTBED_EventInformation *event;
270 uint64_t op_id; 270 uint64_t op_id;
271 271
272 op_id = GNUNET_ntohll (msg->operation_id); 272 op_id = GNUNET_ntohll (msg->operation_id);
273 LOG_DEBUG ("Operation %ul successful\n", op_id); 273 LOG_DEBUG ("Operation %ul successful\n", op_id);
274 if (NULL == (opc = find_opc (c, op_id))) 274 if (NULL == (opc = find_opc (c, op_id)))
@@ -284,28 +284,29 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
284 switch (opc->type) 284 switch (opc->type)
285 { 285 {
286 case OP_FORWARDED: 286 case OP_FORWARDED:
287 { 287 {
288 struct ForwardedOperationData *fo_data; 288 struct ForwardedOperationData *fo_data;
289 289
290 fo_data = opc->data; 290 fo_data = opc->data;
291 if (NULL != fo_data->cc) 291 if (NULL != fo_data->cc)
292 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); 292 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
293 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); 293 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
294 GNUNET_free (fo_data); 294 GNUNET_free (fo_data);
295 GNUNET_free (opc); 295 GNUNET_free (opc);
296 return GNUNET_YES; 296 return GNUNET_YES;
297 } 297 }
298 break; 298 break;
299 case OP_PEER_DESTROY: 299 case OP_PEER_DESTROY:
300 { 300 {
301 struct GNUNET_TESTBED_Peer *peer; 301 struct GNUNET_TESTBED_Peer *peer;
302 peer = opc->data; 302
303 GNUNET_free (peer); 303 peer = opc->data;
304 opc->data = NULL; 304 GNUNET_free (peer);
305 //PEERDESTROYDATA 305 opc->data = NULL;
306 } 306 //PEERDESTROYDATA
307 }
307 break; 308 break;
308 case OP_LINK_CONTROLLERS: 309 case OP_LINK_CONTROLLERS:
309 break; 310 break;
310 default: 311 default:
311 GNUNET_assert (0); 312 GNUNET_assert (0);
@@ -325,8 +326,8 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
325 if (NULL != c->cc) 326 if (NULL != c->cc)
326 c->cc (c->cc_cls, event); 327 c->cc (c->cc_cls, event);
327 GNUNET_free (event); 328 GNUNET_free (event);
328 } 329 }
329 return GNUNET_YES; 330 return GNUNET_YES;
330} 331}
331 332
332 333
@@ -341,8 +342,8 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
341 */ 342 */
342static int 343static int
343handle_peer_create_success (struct GNUNET_TESTBED_Controller *c, 344handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
344 const struct 345 const struct
345 GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg) 346 GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg)
346{ 347{
347 struct OperationContext *opc; 348 struct OperationContext *opc;
348 struct PeerCreateData *data; 349 struct PeerCreateData *data;
@@ -351,8 +352,8 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
351 void *cls; 352 void *cls;
352 uint64_t op_id; 353 uint64_t op_id;
353 354
354 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) 355 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) ==
355 == ntohs (msg->header.size)); 356 ntohs (msg->header.size));
356 op_id = GNUNET_ntohll (msg->operation_id); 357 op_id = GNUNET_ntohll (msg->operation_id);
357 if (NULL == (opc = find_opc (c, op_id))) 358 if (NULL == (opc = find_opc (c, op_id)))
358 { 359 {
@@ -362,14 +363,14 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
362 if (OP_FORWARDED == opc->type) 363 if (OP_FORWARDED == opc->type)
363 { 364 {
364 struct ForwardedOperationData *fo_data; 365 struct ForwardedOperationData *fo_data;
365 366
366 fo_data = opc->data; 367 fo_data = opc->data;
367 if (NULL != fo_data->cc) 368 if (NULL != fo_data->cc)
368 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); 369 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
369 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); 370 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
370 GNUNET_free (fo_data); 371 GNUNET_free (fo_data);
371 GNUNET_free (opc); 372 GNUNET_free (opc);
372 return GNUNET_YES; 373 return GNUNET_YES;
373 } 374 }
374 GNUNET_assert (OP_PEER_CREATE == opc->type); 375 GNUNET_assert (OP_PEER_CREATE == opc->type);
375 GNUNET_assert (NULL != opc->data); 376 GNUNET_assert (NULL != opc->data);
@@ -380,7 +381,7 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
380 peer->state = PS_CREATED; 381 peer->state = PS_CREATED;
381 cb = data->cb; 382 cb = data->cb;
382 cls = data->cls; 383 cls = data->cls;
383 GNUNET_free (opc->data); 384 GNUNET_free (opc->data);
384 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 385 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
385 opc->state = OPC_STATE_FINISHED; 386 opc->state = OPC_STATE_FINISHED;
386 if (NULL != cb) 387 if (NULL != cb)
@@ -400,15 +401,15 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
400 */ 401 */
401static int 402static int
402handle_peer_event (struct GNUNET_TESTBED_Controller *c, 403handle_peer_event (struct GNUNET_TESTBED_Controller *c,
403 const struct GNUNET_TESTBED_PeerEventMessage *msg) 404 const struct GNUNET_TESTBED_PeerEventMessage *msg)
404{ 405{
405 struct OperationContext *opc; 406 struct OperationContext *opc;
406 struct GNUNET_TESTBED_Peer *peer; 407 struct GNUNET_TESTBED_Peer *peer;
407 struct GNUNET_TESTBED_EventInformation event; 408 struct GNUNET_TESTBED_EventInformation event;
408 uint64_t op_id; 409 uint64_t op_id;
409 410
410 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage) 411 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage) ==
411 == ntohs (msg->header.size)); 412 ntohs (msg->header.size));
412 op_id = GNUNET_ntohll (msg->operation_id); 413 op_id = GNUNET_ntohll (msg->operation_id);
413 if (NULL == (opc = find_opc (c, op_id))) 414 if (NULL == (opc = find_opc (c, op_id)))
414 { 415 {
@@ -418,14 +419,14 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
418 if (OP_FORWARDED == opc->type) 419 if (OP_FORWARDED == opc->type)
419 { 420 {
420 struct ForwardedOperationData *fo_data; 421 struct ForwardedOperationData *fo_data;
421 422
422 fo_data = opc->data; 423 fo_data = opc->data;
423 if (NULL != fo_data->cc) 424 if (NULL != fo_data->cc)
424 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); 425 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
425 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); 426 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
426 GNUNET_free (fo_data); 427 GNUNET_free (fo_data);
427 GNUNET_free (opc); 428 GNUNET_free (opc);
428 return GNUNET_YES; 429 return GNUNET_YES;
429 } 430 }
430 GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); 431 GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type));
431 peer = opc->data; 432 peer = opc->data;
@@ -439,20 +440,21 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
439 event.details.peer_start.peer = peer; 440 event.details.peer_start.peer = peer;
440 break; 441 break;
441 case GNUNET_TESTBED_ET_PEER_STOP: 442 case GNUNET_TESTBED_ET_PEER_STOP:
442 peer->state = PS_STOPPED; 443 peer->state = PS_STOPPED;
443 event.details.peer_stop.peer = peer; 444 event.details.peer_stop.peer = peer;
444 break; 445 break;
445 default: 446 default:
446 GNUNET_assert (0); /* We should never reach this state */ 447 GNUNET_assert (0); /* We should never reach this state */
447 } 448 }
448 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 449 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
449 opc->state = OPC_STATE_FINISHED; 450 opc->state = OPC_STATE_FINISHED;
450 if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP) 451 if (0 !=
451 & c->event_mask)) 452 ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP) &
453 c->event_mask))
452 { 454 {
453 if (NULL != c->cc) 455 if (NULL != c->cc)
454 c->cc (c->cc_cls, &event); 456 c->cc (c->cc_cls, &event);
455 } 457 }
456 return GNUNET_YES; 458 return GNUNET_YES;
457} 459}
458 460
@@ -483,8 +485,8 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
483 } 485 }
484 data = opc->data; 486 data = opc->data;
485 GNUNET_assert (NULL != data); 487 GNUNET_assert (NULL != data);
486 GNUNET_assert ((ntohl (msg->peer1) == data->p1->unique_id) 488 GNUNET_assert ((ntohl (msg->peer1) == data->p1->unique_id) &&
487 && (ntohl (msg->peer2) == data->p2->unique_id)); 489 (ntohl (msg->peer2) == data->p2->unique_id));
488 event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type); 490 event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
489 switch (event.type) 491 switch (event.type)
490 { 492 {
@@ -502,8 +504,9 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
502 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 504 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
503 opc->state = OPC_STATE_FINISHED; 505 opc->state = OPC_STATE_FINISHED;
504 GNUNET_free (data); 506 GNUNET_free (data);
505 if (0 != ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) 507 if (0 !=
506 & c->event_mask)) 508 ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) &
509 c->event_mask))
507 { 510 {
508 if (NULL != c->cc) 511 if (NULL != c->cc)
509 c->cc (c->cc_cls, &event); 512 c->cc (c->cc_cls, &event);
@@ -523,7 +526,8 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
523 */ 526 */
524static int 527static int
525handle_peer_config (struct GNUNET_TESTBED_Controller *c, 528handle_peer_config (struct GNUNET_TESTBED_Controller *c,
526 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) 529 const struct
530 GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
527{ 531{
528 struct OperationContext *opc; 532 struct OperationContext *opc;
529 struct GNUNET_TESTBED_Peer *peer; 533 struct GNUNET_TESTBED_Peer *peer;
@@ -531,7 +535,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
531 struct PeerInfoData2 *response_data; 535 struct PeerInfoData2 *response_data;
532 struct GNUNET_TESTBED_EventInformation info; 536 struct GNUNET_TESTBED_EventInformation info;
533 uint64_t op_id; 537 uint64_t op_id;
534 538
535 op_id = GNUNET_ntohll (msg->operation_id); 539 op_id = GNUNET_ntohll (msg->operation_id);
536 if (NULL == (opc = find_opc (c, op_id))) 540 if (NULL == (opc = find_opc (c, op_id)))
537 { 541 {
@@ -541,14 +545,14 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
541 if (OP_FORWARDED == opc->type) 545 if (OP_FORWARDED == opc->type)
542 { 546 {
543 struct ForwardedOperationData *fo_data; 547 struct ForwardedOperationData *fo_data;
544 548
545 fo_data = opc->data; 549 fo_data = opc->data;
546 if (NULL != fo_data->cc) 550 if (NULL != fo_data->cc)
547 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); 551 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
548 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); 552 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
549 GNUNET_free (fo_data); 553 GNUNET_free (fo_data);
550 GNUNET_free (opc); 554 GNUNET_free (opc);
551 return GNUNET_YES; 555 return GNUNET_YES;
552 } 556 }
553 data = opc->data; 557 data = opc->data;
554 GNUNET_assert (NULL != data); 558 GNUNET_assert (NULL != data);
@@ -572,34 +576,35 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
572 switch (response_data->pit) 576 switch (response_data->pit)
573 { 577 {
574 case GNUNET_TESTBED_PIT_IDENTITY: 578 case GNUNET_TESTBED_PIT_IDENTITY:
575 { 579 {
576 struct GNUNET_PeerIdentity *peer_identity; 580 struct GNUNET_PeerIdentity *peer_identity;
577 581
578 peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 582 peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
579 (void) memcpy (peer_identity, &msg->peer_identity, 583 (void) memcpy (peer_identity, &msg->peer_identity,
580 sizeof (struct GNUNET_PeerIdentity)); 584 sizeof (struct GNUNET_PeerIdentity));
581 response_data->details.peer_identity = peer_identity; 585 response_data->details.peer_identity = peer_identity;
582 info.details.operation_finished.op_result.pid = peer_identity; 586 info.details.operation_finished.op_result.pid = peer_identity;
583 } 587 }
584 break; 588 break;
585 case GNUNET_TESTBED_PIT_CONFIGURATION: 589 case GNUNET_TESTBED_PIT_CONFIGURATION:
586 response_data->details.cfg = /* Freed in oprelease_peer_getinfo */ 590 response_data->details.cfg = /* Freed in oprelease_peer_getinfo */
587 GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg); 591 GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg);
588 info.details.operation_finished.op_result.cfg = response_data->details.cfg; 592 info.details.operation_finished.op_result.cfg = response_data->details.cfg;
589 break; 593 break;
590 case GNUNET_TESTBED_PIT_GENERIC: 594 case GNUNET_TESTBED_PIT_GENERIC:
591 GNUNET_assert (0); /* never reach here */ 595 GNUNET_assert (0); /* never reach here */
592 break; 596 break;
593 } 597 }
594 opc->data = response_data; 598 opc->data = response_data;
595 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 599 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
596 opc->state = OPC_STATE_FINISHED; 600 opc->state = OPC_STATE_FINISHED;
597 if (0 != ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) 601 if (0 !=
598 & c->event_mask)) 602 ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) &
603 c->event_mask))
599 { 604 {
600 if (NULL != c->cc) 605 if (NULL != c->cc)
601 c->cc (c->cc_cls, &info); 606 c->cc (c->cc_cls, &info);
602 } 607 }
603 return GNUNET_YES; 608 return GNUNET_YES;
604} 609}
605 610
@@ -615,15 +620,15 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
615 */ 620 */
616static int 621static int
617handle_op_fail_event (struct GNUNET_TESTBED_Controller *c, 622handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
618 const struct 623 const struct GNUNET_TESTBED_OperationFailureEventMessage
619 GNUNET_TESTBED_OperationFailureEventMessage *msg) 624 *msg)
620{ 625{
621 struct OperationContext *opc; 626 struct OperationContext *opc;
622 char *emsg; 627 char *emsg;
623 uint64_t op_id; 628 uint64_t op_id;
624 struct GNUNET_TESTBED_EventInformation event; 629 struct GNUNET_TESTBED_EventInformation event;
625 uint16_t msize; 630 uint16_t msize;
626 631
627 op_id = GNUNET_ntohll (msg->operation_id); 632 op_id = GNUNET_ntohll (msg->operation_id);
628 if (NULL == (opc = find_opc (c, op_id))) 633 if (NULL == (opc = find_opc (c, op_id)))
629 { 634 {
@@ -633,14 +638,14 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
633 if (OP_FORWARDED == opc->type) 638 if (OP_FORWARDED == opc->type)
634 { 639 {
635 struct ForwardedOperationData *fo_data; 640 struct ForwardedOperationData *fo_data;
636 641
637 fo_data = opc->data; 642 fo_data = opc->data;
638 if (NULL != fo_data->cc) 643 if (NULL != fo_data->cc)
639 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); 644 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
640 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); 645 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
641 GNUNET_free (fo_data); 646 GNUNET_free (fo_data);
642 GNUNET_free (opc); 647 GNUNET_free (opc);
643 return GNUNET_YES; 648 return GNUNET_YES;
644 } 649 }
645 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 650 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
646 opc->state = OPC_STATE_FINISHED; 651 opc->state = OPC_STATE_FINISHED;
@@ -658,8 +663,8 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
658 emsg = (char *) &msg[1]; 663 emsg = (char *) &msg[1];
659 GNUNET_assert ('\0' == emsg[msize - 1]); 664 GNUNET_assert ('\0' == emsg[msize - 1]);
660 } 665 }
661 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) 666 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
662 && (NULL != c->cc)) 667 (NULL != c->cc))
663 { 668 {
664 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 669 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
665 event.details.operation_finished.operation = opc->op; 670 event.details.operation_finished.operation = opc->op;
@@ -668,7 +673,7 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
668 event.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; 673 event.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC;
669 event.details.operation_finished.op_result.generic = NULL; 674 event.details.operation_finished.op_result.generic = NULL;
670 c->cc (c->cc_cls, &event); 675 c->cc (c->cc_cls, &event);
671 } 676 }
672 return GNUNET_YES; 677 return GNUNET_YES;
673} 678}
674 679
@@ -679,7 +684,7 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
679 * @param cls the controller handler 684 * @param cls the controller handler
680 * @param msg message received, NULL on timeout or fatal error 685 * @param msg message received, NULL on timeout or fatal error
681 */ 686 */
682static void 687static void
683message_handler (void *cls, const struct GNUNET_MessageHeader *msg) 688message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
684{ 689{
685 struct GNUNET_TESTBED_Controller *c = cls; 690 struct GNUNET_TESTBED_Controller *c = cls;
@@ -698,54 +703,67 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
698 switch (ntohs (msg->type)) 703 switch (ntohs (msg->type))
699 { 704 {
700 case GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM: 705 case GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM:
701 GNUNET_assert (msize >= sizeof (struct 706 GNUNET_assert (msize >=
702 GNUNET_TESTBED_HostConfirmedMessage)); 707 sizeof (struct GNUNET_TESTBED_HostConfirmedMessage));
703 status = 708 status =
704 handle_addhostconfirm (c, (const struct GNUNET_TESTBED_HostConfirmedMessage *) msg); 709 handle_addhostconfirm (c,
710 (const struct GNUNET_TESTBED_HostConfirmedMessage
711 *) msg);
705 break; 712 break;
706 case GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS: 713 case GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS:
707 GNUNET_assert 714 GNUNET_assert (msize ==
708 (msize == sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage)); 715 sizeof (struct
716 GNUNET_TESTBED_GenericOperationSuccessEventMessage));
709 status = 717 status =
710 handle_opsuccess (c, (const struct 718 handle_opsuccess (c,
711 GNUNET_TESTBED_GenericOperationSuccessEventMessage 719 (const struct
712 *) msg); 720 GNUNET_TESTBED_GenericOperationSuccessEventMessage *)
721 msg);
713 break; 722 break;
714 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS: 723 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS:
715 GNUNET_assert (msize == 724 GNUNET_assert (msize ==
716 sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)); 725 sizeof (struct
726 GNUNET_TESTBED_PeerCreateSuccessEventMessage));
717 status = 727 status =
718 handle_peer_create_success 728 handle_peer_create_success (c,
719 (c, (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *)msg); 729 (const struct
730 GNUNET_TESTBED_PeerCreateSuccessEventMessage
731 *) msg);
720 break; 732 break;
721 case GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT: 733 case GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT:
722 GNUNET_assert (msize == sizeof (struct GNUNET_TESTBED_PeerEventMessage)); 734 GNUNET_assert (msize == sizeof (struct GNUNET_TESTBED_PeerEventMessage));
723 status = 735 status =
724 handle_peer_event (c, (const struct GNUNET_TESTBED_PeerEventMessage *) msg); 736 handle_peer_event (c,
725 737 (const struct GNUNET_TESTBED_PeerEventMessage *)
738 msg);
739
726 break; 740 break;
727 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG: 741 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG:
728 GNUNET_assert (msize >= 742 GNUNET_assert (msize >=
729 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage)); 743 sizeof (struct
730 status = 744 GNUNET_TESTBED_PeerConfigurationInformationMessage));
731 handle_peer_config 745 status =
732 (c, (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) 746 handle_peer_config (c,
733 msg); 747 (const struct
748 GNUNET_TESTBED_PeerConfigurationInformationMessage
749 *) msg);
734 break; 750 break;
735 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT: 751 case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT:
736 GNUNET_assert (msize == 752 GNUNET_assert (msize ==
737 sizeof (struct GNUNET_TESTBED_ConnectionEventMessage)); 753 sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
738 status = 754 status =
739 handle_peer_conevent (c, (const struct 755 handle_peer_conevent (c,
740 GNUNET_TESTBED_ConnectionEventMessage *) msg); 756 (const struct
757 GNUNET_TESTBED_ConnectionEventMessage *) msg);
741 break; 758 break;
742 case GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONEVENT: 759 case GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONEVENT:
743 GNUNET_assert (msize >= 760 GNUNET_assert (msize >=
744 sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage)); 761 sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage));
745 status = 762 status =
746 handle_op_fail_event (c, (const struct 763 handle_op_fail_event (c,
747 GNUNET_TESTBED_OperationFailureEventMessage *) 764 (const struct
748 msg); 765 GNUNET_TESTBED_OperationFailureEventMessage *)
766 msg);
749 break; 767 break;
750 default: 768 default:
751 GNUNET_assert (0); 769 GNUNET_assert (0);
@@ -754,7 +772,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
754 { 772 {
755 c->in_receive = GNUNET_YES; 773 c->in_receive = GNUNET_YES;
756 GNUNET_CLIENT_receive (c->client, &message_handler, c, 774 GNUNET_CLIENT_receive (c->client, &message_handler, c,
757 GNUNET_TIME_UNIT_FOREVER_REL); 775 GNUNET_TIME_UNIT_FOREVER_REL);
758 } 776 }
759} 777}
760 778
@@ -778,38 +796,36 @@ transmit_ready_notify (void *cls, size_t size, void *buf)
778 c->th = NULL; 796 c->th = NULL;
779 mq_entry = c->mq_head; 797 mq_entry = c->mq_head;
780 GNUNET_assert (NULL != mq_entry); 798 GNUNET_assert (NULL != mq_entry);
781 if ((0 == size) && (NULL == buf)) /* Timeout */ 799 if ((0 == size) && (NULL == buf)) /* Timeout */
782 { 800 {
783 LOG_DEBUG ("Message sending timed out -- retrying\n"); 801 LOG_DEBUG ("Message sending timed out -- retrying\n");
784 c->th = 802 c->th =
785 GNUNET_CLIENT_notify_transmit_ready (c->client, 803 GNUNET_CLIENT_notify_transmit_ready (c->client,
786 ntohs (mq_entry->msg->size), 804 ntohs (mq_entry->msg->size),
787 TIMEOUT_REL, 805 TIMEOUT_REL, GNUNET_YES,
788 GNUNET_YES, &transmit_ready_notify, 806 &transmit_ready_notify, c);
789 c);
790 return 0; 807 return 0;
791 } 808 }
792 GNUNET_assert (ntohs (mq_entry->msg->size) <= size); 809 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
793 size = ntohs (mq_entry->msg->size); 810 size = ntohs (mq_entry->msg->size);
794 memcpy (buf, mq_entry->msg, size); 811 memcpy (buf, mq_entry->msg, size);
795 LOG_DEBUG ("Message of type: %u and size: %u sent\n", 812 LOG_DEBUG ("Message of type: %u and size: %u sent\n",
796 ntohs (mq_entry->msg->type), size); 813 ntohs (mq_entry->msg->type), size);
797 GNUNET_free (mq_entry->msg); 814 GNUNET_free (mq_entry->msg);
798 GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, mq_entry); 815 GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, mq_entry);
799 GNUNET_free (mq_entry); 816 GNUNET_free (mq_entry);
800 mq_entry = c->mq_head; 817 mq_entry = c->mq_head;
801 if (NULL != mq_entry) 818 if (NULL != mq_entry)
802 c->th = 819 c->th =
803 GNUNET_CLIENT_notify_transmit_ready (c->client, 820 GNUNET_CLIENT_notify_transmit_ready (c->client,
804 ntohs (mq_entry->msg->size), 821 ntohs (mq_entry->msg->size),
805 TIMEOUT_REL, 822 TIMEOUT_REL, GNUNET_YES,
806 GNUNET_YES, &transmit_ready_notify, 823 &transmit_ready_notify, c);
807 c);
808 if (GNUNET_NO == c->in_receive) 824 if (GNUNET_NO == c->in_receive)
809 { 825 {
810 c->in_receive = GNUNET_YES; 826 c->in_receive = GNUNET_YES;
811 GNUNET_CLIENT_receive (c->client, &message_handler, c, 827 GNUNET_CLIENT_receive (c->client, &message_handler, c,
812 GNUNET_TIME_UNIT_FOREVER_REL); 828 GNUNET_TIME_UNIT_FOREVER_REL);
813 } 829 }
814 return size; 830 return size;
815} 831}
@@ -823,7 +839,7 @@ transmit_ready_notify (void *cls, size_t size, void *buf)
823 */ 839 */
824void 840void
825GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, 841GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
826 struct GNUNET_MessageHeader *msg) 842 struct GNUNET_MessageHeader *msg)
827{ 843{
828 struct MessageQueue *mq_entry; 844 struct MessageQueue *mq_entry;
829 uint16_t type; 845 uint16_t type;
@@ -832,7 +848,7 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
832 type = ntohs (msg->type); 848 type = ntohs (msg->type);
833 size = ntohs (msg->size); 849 size = ntohs (msg->size);
834 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && 850 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
835 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); 851 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
836 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue)); 852 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
837 mq_entry->msg = msg; 853 mq_entry->msg = msg;
838 LOG (GNUNET_ERROR_TYPE_DEBUG, 854 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -841,11 +857,11 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
841 GNUNET_CONTAINER_DLL_insert_tail (controller->mq_head, controller->mq_tail, 857 GNUNET_CONTAINER_DLL_insert_tail (controller->mq_head, controller->mq_tail,
842 mq_entry); 858 mq_entry);
843 if (NULL == controller->th) 859 if (NULL == controller->th)
844 controller->th = 860 controller->th =
845 GNUNET_CLIENT_notify_transmit_ready (controller->client, size, 861 GNUNET_CLIENT_notify_transmit_ready (controller->client, size,
846 TIMEOUT_REL, 862 TIMEOUT_REL, GNUNET_YES,
847 GNUNET_YES, &transmit_ready_notify, 863 &transmit_ready_notify,
848 controller); 864 controller);
849} 865}
850 866
851 867
@@ -861,36 +877,35 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
861 * @param cc the callback to call when reply is available 877 * @param cc the callback to call when reply is available
862 * @param cc_cls the closure for the above callback 878 * @param cc_cls the closure for the above callback
863 * @return the operation context which can be used to cancel the forwarded 879 * @return the operation context which can be used to cancel the forwarded
864 * operation 880 * operation
865 */ 881 */
866struct OperationContext * 882struct OperationContext *
867GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller 883GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
868 * controller, 884 *controller, uint64_t operation_id,
869 uint64_t operation_id,
870 const struct GNUNET_MessageHeader *msg, 885 const struct GNUNET_MessageHeader *msg,
871 GNUNET_CLIENT_MessageHandler cc, 886 GNUNET_CLIENT_MessageHandler cc,
872 void *cc_cls) 887 void *cc_cls)
873{ 888{
874 struct OperationContext *opc; 889 struct OperationContext *opc;
875 struct ForwardedOperationData *data; 890 struct ForwardedOperationData *data;
876 struct GNUNET_MessageHeader *dup_msg; 891 struct GNUNET_MessageHeader *dup_msg;
877 uint16_t msize; 892 uint16_t msize;
878 893
879 data = GNUNET_malloc (sizeof (struct ForwardedOperationData)); 894 data = GNUNET_malloc (sizeof (struct ForwardedOperationData));
880 data->cc = cc; 895 data->cc = cc;
881 data->cc_cls = cc_cls; 896 data->cc_cls = cc_cls;
882 opc = GNUNET_malloc (sizeof (struct OperationContext)); 897 opc = GNUNET_malloc (sizeof (struct OperationContext));
883 opc->c = controller; 898 opc->c = controller;
884 opc->type = OP_FORWARDED; 899 opc->type = OP_FORWARDED;
885 opc->data = data; 900 opc->data = data;
886 opc->id = operation_id; 901 opc->id = operation_id;
887 msize = ntohs (msg->size); 902 msize = ntohs (msg->size);
888 dup_msg = GNUNET_malloc (msize); 903 dup_msg = GNUNET_malloc (msize);
889 (void) memcpy (dup_msg, msg, msize); 904 (void) memcpy (dup_msg, msg, msize);
890 GNUNET_TESTBED_queue_message_ (opc->c, dup_msg); 905 GNUNET_TESTBED_queue_message_ (opc->c, dup_msg);
891 GNUNET_CONTAINER_DLL_insert_tail (controller->ocq_head, 906 GNUNET_CONTAINER_DLL_insert_tail (controller->ocq_head, controller->ocq_tail,
892 controller->ocq_tail, opc); 907 opc);
893 return opc; 908 return opc;
894} 909}
895 910
896 911
@@ -905,7 +920,7 @@ GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc)
905{ 920{
906 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 921 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
907 GNUNET_free (opc->data); 922 GNUNET_free (opc->data);
908 GNUNET_free (opc); 923 GNUNET_free (opc);
909} 924}
910 925
911 926
@@ -974,9 +989,8 @@ struct GNUNET_TESTBED_ControllerProc
974 * 989 *
975 * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing 990 * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing
976 */ 991 */
977static int 992static int
978helper_mst (void *cls, void *client, 993helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message)
979 const struct GNUNET_MessageHeader *message)
980{ 994{
981 struct GNUNET_TESTBED_ControllerProc *cp = cls; 995 struct GNUNET_TESTBED_ControllerProc *cp = cls;
982 const struct GNUNET_TESTBED_HelperReply *msg; 996 const struct GNUNET_TESTBED_HelperReply *msg;
@@ -984,29 +998,31 @@ helper_mst (void *cls, void *client,
984 char *config; 998 char *config;
985 uLongf config_size; 999 uLongf config_size;
986 uLongf xconfig_size; 1000 uLongf xconfig_size;
987 1001
988 msg = (const struct GNUNET_TESTBED_HelperReply *) message; 1002 msg = (const struct GNUNET_TESTBED_HelperReply *) message;
989 GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) 1003 GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) <
990 < ntohs (msg->header.size)); 1004 ntohs (msg->header.size));
991 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY 1005 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY ==
992 == ntohs (msg->header.type)); 1006 ntohs (msg->header.type));
993 config_size = (uLongf) ntohs (msg->config_size); 1007 config_size = (uLongf) ntohs (msg->config_size);
994 xconfig_size = (uLongf) (ntohs (msg->header.size) 1008 xconfig_size =
995 - sizeof (struct GNUNET_TESTBED_HelperReply)); 1009 (uLongf) (ntohs (msg->header.size) -
1010 sizeof (struct GNUNET_TESTBED_HelperReply));
996 config = GNUNET_malloc (config_size); 1011 config = GNUNET_malloc (config_size);
997 GNUNET_assert (Z_OK == uncompress ((Bytef *) config, &config_size, 1012 GNUNET_assert (Z_OK ==
998 (const Bytef *) &msg[1], xconfig_size)); 1013 uncompress ((Bytef *) config, &config_size,
1014 (const Bytef *) &msg[1], xconfig_size));
999 GNUNET_assert (NULL == cp->cfg); 1015 GNUNET_assert (NULL == cp->cfg);
1000 cp->cfg = GNUNET_CONFIGURATION_create (); 1016 cp->cfg = GNUNET_CONFIGURATION_create ();
1001 GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->cfg, config, 1017 GNUNET_assert (GNUNET_CONFIGURATION_deserialize
1002 config_size, GNUNET_NO)); 1018 (cp->cfg, config, config_size, GNUNET_NO));
1003 GNUNET_free (config); 1019 GNUNET_free (config);
1004 if ((NULL == cp->host) || 1020 if ((NULL == cp->host) ||
1005 (NULL == (hostname = GNUNET_TESTBED_host_get_hostname_ (cp->host)))) 1021 (NULL == (hostname = GNUNET_TESTBED_host_get_hostname_ (cp->host))))
1006 hostname = "localhost"; 1022 hostname = "localhost";
1007 /* Change the hostname so that we can connect to it */ 1023 /* Change the hostname so that we can connect to it */
1008 GNUNET_CONFIGURATION_set_value_string (cp->cfg, "testbed", "hostname", 1024 GNUNET_CONFIGURATION_set_value_string (cp->cfg, "testbed", "hostname",
1009 hostname); 1025 hostname);
1010 cp->cb (cp->cls, cp->cfg, GNUNET_OK); 1026 cp->cb (cp->cls, cp->cfg, GNUNET_OK);
1011 return GNUNET_OK; 1027 return GNUNET_OK;
1012} 1028}
@@ -1014,17 +1030,17 @@ helper_mst (void *cls, void *client,
1014 1030
1015/** 1031/**
1016 * Continuation function from GNUNET_HELPER_send() 1032 * Continuation function from GNUNET_HELPER_send()
1017 * 1033 *
1018 * @param cls closure 1034 * @param cls closure
1019 * @param result GNUNET_OK on success, 1035 * @param result GNUNET_OK on success,
1020 * GNUNET_NO if helper process died 1036 * GNUNET_NO if helper process died
1021 * GNUNET_SYSERR during GNUNET_HELPER_stop 1037 * GNUNET_SYSERR during GNUNET_HELPER_stop
1022 */ 1038 */
1023static void 1039static void
1024clear_msg (void *cls, int result) 1040clear_msg (void *cls, int result)
1025{ 1041{
1026 struct GNUNET_TESTBED_ControllerProc *cp = cls; 1042 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1027 1043
1028 GNUNET_assert (NULL != cp->shandle); 1044 GNUNET_assert (NULL != cp->shandle);
1029 cp->shandle = NULL; 1045 cp->shandle = NULL;
1030 GNUNET_free (cp->msg); 1046 GNUNET_free (cp->msg);
@@ -1037,7 +1053,7 @@ clear_msg (void *cls, int result)
1037 * 1053 *
1038 * @param cls the closure from GNUNET_HELPER_start() 1054 * @param cls the closure from GNUNET_HELPER_start()
1039 */ 1055 */
1040static void 1056static void
1041helper_exp_cb (void *cls) 1057helper_exp_cb (void *cls)
1042{ 1058{
1043 struct GNUNET_TESTBED_ControllerProc *cp = cls; 1059 struct GNUNET_TESTBED_ControllerProc *cp = cls;
@@ -1059,7 +1075,7 @@ helper_exp_cb (void *cls)
1059 * 1075 *
1060 * @param cls the closure from GNUNET_TESTBED_operation_create_() 1076 * @param cls the closure from GNUNET_TESTBED_operation_create_()
1061 */ 1077 */
1062static void 1078static void
1063opstart_link_controllers (void *cls) 1079opstart_link_controllers (void *cls)
1064{ 1080{
1065 struct OperationContext *opc = cls; 1081 struct OperationContext *opc = cls;
@@ -1079,7 +1095,7 @@ opstart_link_controllers (void *cls)
1079 * 1095 *
1080 * @param cls the closure from GNUNET_TESTBED_operation_create_() 1096 * @param cls the closure from GNUNET_TESTBED_operation_create_()
1081 */ 1097 */
1082static void 1098static void
1083oprelease_link_controllers (void *cls) 1099oprelease_link_controllers (void *cls)
1084{ 1100{
1085 struct OperationContext *opc = cls; 1101 struct OperationContext *opc = cls;
@@ -1115,24 +1131,24 @@ oprelease_link_controllers (void *cls)
1115 */ 1131 */
1116struct GNUNET_TESTBED_ControllerProc * 1132struct GNUNET_TESTBED_ControllerProc *
1117GNUNET_TESTBED_controller_start (const char *controller_ip, 1133GNUNET_TESTBED_controller_start (const char *controller_ip,
1118 struct GNUNET_TESTBED_Host *host, 1134 struct GNUNET_TESTBED_Host *host,
1119 const struct GNUNET_CONFIGURATION_Handle *cfg, 1135 const struct GNUNET_CONFIGURATION_Handle *cfg,
1120 GNUNET_TESTBED_ControllerStatusCallback cb, 1136 GNUNET_TESTBED_ControllerStatusCallback cb,
1121 void *cls) 1137 void *cls)
1122{ 1138{
1123 struct GNUNET_TESTBED_ControllerProc *cp; 1139 struct GNUNET_TESTBED_ControllerProc *cp;
1124 struct GNUNET_TESTBED_HelperInit *msg; 1140 struct GNUNET_TESTBED_HelperInit *msg;
1125 1141
1126 cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); 1142 cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc));
1127 if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host))) 1143 if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host)))
1128 { 1144 {
1129 char * const binary_argv[] = { 1145 char *const binary_argv[] = {
1130 "gnunet-testbed-helper", NULL 1146 "gnunet-testbed-helper", NULL
1131 }; 1147 };
1132 1148
1133 cp->helper = GNUNET_HELPER_start (GNUNET_YES, 1149 cp->helper =
1134 "gnunet-testbed-helper", binary_argv, 1150 GNUNET_HELPER_start (GNUNET_YES, "gnunet-testbed-helper", binary_argv,
1135 &helper_mst, &helper_exp_cb, cp); 1151 &helper_mst, &helper_exp_cb, cp);
1136 } 1152 }
1137 else 1153 else
1138 { 1154 {
@@ -1146,7 +1162,7 @@ GNUNET_TESTBED_controller_start (const char *controller_ip,
1146 GNUNET_asprintf (&cp->port, "%u", GNUNET_TESTBED_host_get_ssh_port_ (host)); 1162 GNUNET_asprintf (&cp->port, "%u", GNUNET_TESTBED_host_get_ssh_port_ (host));
1147 if (NULL == username) 1163 if (NULL == username)
1148 GNUNET_asprintf (&cp->dst, "%s", hostname); 1164 GNUNET_asprintf (&cp->dst, "%s", hostname);
1149 else 1165 else
1150 GNUNET_asprintf (&cp->dst, "%s@%s", username, hostname); 1166 GNUNET_asprintf (&cp->dst, "%s@%s", username, hostname);
1151 LOG_DEBUG ("Starting SSH to destination %s\n", cp->dst); 1167 LOG_DEBUG ("Starting SSH to destination %s\n", cp->dst);
1152 argp = 0; 1168 argp = 0;
@@ -1159,9 +1175,9 @@ GNUNET_TESTBED_controller_start (const char *controller_ip,
1159 remote_args[argp++] = "gnunet-testbed-helper"; 1175 remote_args[argp++] = "gnunet-testbed-helper";
1160 remote_args[argp++] = NULL; 1176 remote_args[argp++] = NULL;
1161 GNUNET_assert (argp == 8); 1177 GNUNET_assert (argp == 8);
1162 cp->helper = GNUNET_HELPER_start (GNUNET_NO, 1178 cp->helper =
1163 "ssh", remote_args, 1179 GNUNET_HELPER_start (GNUNET_NO, "ssh", remote_args, &helper_mst,
1164 &helper_mst, &helper_exp_cb, cp); 1180 &helper_exp_cb, cp);
1165 } 1181 }
1166 if (NULL == cp->helper) 1182 if (NULL == cp->helper)
1167 { 1183 {
@@ -1175,8 +1191,8 @@ GNUNET_TESTBED_controller_start (const char *controller_ip,
1175 cp->cls = cls; 1191 cp->cls = cls;
1176 msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, cfg); 1192 msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, cfg);
1177 cp->msg = &msg->header; 1193 cp->msg = &msg->header;
1178 cp->shandle = GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, 1194 cp->shandle =
1179 &clear_msg, cp); 1195 GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
1180 if (NULL == cp->shandle) 1196 if (NULL == cp->shandle)
1181 { 1197 {
1182 GNUNET_free (msg); 1198 GNUNET_free (msg);
@@ -1226,11 +1242,11 @@ GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc)
1226 * @return handle to the controller 1242 * @return handle to the controller
1227 */ 1243 */
1228struct GNUNET_TESTBED_Controller * 1244struct GNUNET_TESTBED_Controller *
1229GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 1245GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle
1230 struct GNUNET_TESTBED_Host *host, 1246 *cfg, struct GNUNET_TESTBED_Host *host,
1231 uint64_t event_mask, 1247 uint64_t event_mask,
1232 GNUNET_TESTBED_ControllerCallback cc, 1248 GNUNET_TESTBED_ControllerCallback cc,
1233 void *cc_cls) 1249 void *cc_cls)
1234{ 1250{
1235 struct GNUNET_TESTBED_Controller *controller; 1251 struct GNUNET_TESTBED_Controller *controller;
1236 struct GNUNET_TESTBED_InitMessage *msg; 1252 struct GNUNET_TESTBED_InitMessage *msg;
@@ -1259,7 +1275,7 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
1259 controller->cc_cls = cc_cls; 1275 controller->cc_cls = cc_cls;
1260 controller->event_mask = event_mask; 1276 controller->event_mask = event_mask;
1261 controller->cfg = GNUNET_CONFIGURATION_dup (cfg); 1277 controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
1262 controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg); 1278 controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg);
1263 if (NULL == controller->client) 1279 if (NULL == controller->client)
1264 { 1280 {
1265 GNUNET_TESTBED_controller_disconnect (controller); 1281 GNUNET_TESTBED_controller_disconnect (controller);
@@ -1271,8 +1287,8 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
1271 if (NULL == host) /* If the above host create fails */ 1287 if (NULL == host) /* If the above host create fails */
1272 { 1288 {
1273 LOG (GNUNET_ERROR_TYPE_WARNING, 1289 LOG (GNUNET_ERROR_TYPE_WARNING,
1274 "Treating NULL host as localhost. Multiple references to localhost " 1290 "Treating NULL host as localhost. Multiple references to localhost "
1275 "may break when localhost freed before calling disconnect \n"); 1291 "may break when localhost freed before calling disconnect \n");
1276 host = GNUNET_TESTBED_host_lookup_by_id_ (0); 1292 host = GNUNET_TESTBED_host_lookup_by_id_ (0);
1277 } 1293 }
1278 else 1294 else
@@ -1284,24 +1300,26 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
1284 GNUNET_TESTBED_mark_host_registered_at_ (host, controller); 1300 GNUNET_TESTBED_mark_host_registered_at_ (host, controller);
1285 controller->host = host; 1301 controller->host = host;
1286 controller->opq_parallel_operations = 1302 controller->opq_parallel_operations =
1287 GNUNET_TESTBED_operation_queue_create_ ((unsigned int) 1303 GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
1288 max_parallel_operations); 1304 max_parallel_operations);
1289 controller->opq_parallel_service_connections = 1305 controller->opq_parallel_service_connections =
1290 GNUNET_TESTBED_operation_queue_create_ ((unsigned int) 1306 GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
1291 max_parallel_service_connections); 1307 max_parallel_service_connections);
1292 controller_hostname = GNUNET_TESTBED_host_get_hostname_ (host); 1308 controller_hostname = GNUNET_TESTBED_host_get_hostname_ (host);
1293 if (NULL == controller_hostname) 1309 if (NULL == controller_hostname)
1294 controller_hostname = "127.0.0.1"; 1310 controller_hostname = "127.0.0.1";
1295 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage) 1311 msg =
1296 + strlen (controller_hostname) + 1); 1312 GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage) +
1313 strlen (controller_hostname) + 1);
1297 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); 1314 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
1298 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage) 1315 msg->header.size =
1299 + strlen (controller_hostname) + 1); 1316 htons (sizeof (struct GNUNET_TESTBED_InitMessage) +
1317 strlen (controller_hostname) + 1);
1300 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); 1318 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1301 msg->event_mask = GNUNET_htonll (controller->event_mask); 1319 msg->event_mask = GNUNET_htonll (controller->event_mask);
1302 strcpy ((char *) &msg[1], controller_hostname); 1320 strcpy ((char *) &msg[1], controller_hostname);
1303 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) 1321 GNUNET_TESTBED_queue_message_ (controller,
1304 msg); 1322 (struct GNUNET_MessageHeader *) msg);
1305 return controller; 1323 return controller;
1306} 1324}
1307 1325
@@ -1312,7 +1330,7 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
1312 * should not be run for each peer but instead be shared 1330 * should not be run for each peer but instead be shared
1313 * across N peers on the specified host. This function 1331 * across N peers on the specified host. This function
1314 * must be called before any peers are created at the host. 1332 * must be called before any peers are created at the host.
1315 * 1333 *
1316 * @param controller controller to configure 1334 * @param controller controller to configure
1317 * @param service_name name of the service to share 1335 * @param service_name name of the service to share
1318 * @param num_peers number of peers that should share one instance 1336 * @param num_peers number of peers that should share one instance
@@ -1320,24 +1338,27 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
1320 * use 0 to disable the service 1338 * use 0 to disable the service
1321 */ 1339 */
1322void 1340void
1323GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller, 1341GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller
1324 const char *service_name, 1342 *controller,
1325 uint32_t num_peers) 1343 const char *service_name,
1344 uint32_t num_peers)
1326{ 1345{
1327 struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg; 1346 struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1328 uint16_t service_name_size; 1347 uint16_t service_name_size;
1329 uint16_t msg_size; 1348 uint16_t msg_size;
1330 1349
1331 service_name_size = strlen (service_name) + 1; 1350 service_name_size = strlen (service_name) + 1;
1332 msg_size = sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage) 1351 msg_size =
1333 + service_name_size; 1352 sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage) +
1353 service_name_size;
1334 msg = GNUNET_malloc (msg_size); 1354 msg = GNUNET_malloc (msg_size);
1335 msg->header.size = htons (msg_size); 1355 msg->header.size = htons (msg_size);
1336 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE); 1356 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE);
1337 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host)); 1357 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host));
1338 msg->num_peers = htonl (num_peers); 1358 msg->num_peers = htonl (num_peers);
1339 memcpy (&msg[1], service_name, service_name_size); 1359 memcpy (&msg[1], service_name, service_name_size);
1340 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) msg); 1360 GNUNET_TESTBED_queue_message_ (controller,
1361 (struct GNUNET_MessageHeader *) msg);
1341} 1362}
1342 1363
1343 1364
@@ -1347,18 +1368,18 @@ GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *c
1347 * @param controller handle to controller to stop 1368 * @param controller handle to controller to stop
1348 */ 1369 */
1349void 1370void
1350GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller) 1371GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller
1372 *controller)
1351{ 1373{
1352 struct MessageQueue *mq_entry; 1374 struct MessageQueue *mq_entry;
1353 1375
1354 if (NULL != controller->th) 1376 if (NULL != controller->th)
1355 GNUNET_CLIENT_notify_transmit_ready_cancel (controller->th); 1377 GNUNET_CLIENT_notify_transmit_ready_cancel (controller->th);
1356 /* Clear the message queue */ 1378 /* Clear the message queue */
1357 while (NULL != (mq_entry = controller->mq_head)) 1379 while (NULL != (mq_entry = controller->mq_head))
1358 { 1380 {
1359 GNUNET_CONTAINER_DLL_remove (controller->mq_head, 1381 GNUNET_CONTAINER_DLL_remove (controller->mq_head, controller->mq_tail,
1360 controller->mq_tail, 1382 mq_entry);
1361 mq_entry);
1362 GNUNET_free (mq_entry->msg); 1383 GNUNET_free (mq_entry->msg);
1363 GNUNET_free (mq_entry); 1384 GNUNET_free (mq_entry);
1364 } 1385 }
@@ -1369,7 +1390,7 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controll
1369 GNUNET_TESTBED_host_destroy (controller->host); 1390 GNUNET_TESTBED_host_destroy (controller->host);
1370 GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_parallel_operations); 1391 GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_parallel_operations);
1371 GNUNET_TESTBED_operation_queue_destroy_ 1392 GNUNET_TESTBED_operation_queue_destroy_
1372 (controller->opq_parallel_service_connections); 1393 (controller->opq_parallel_service_connections);
1373 GNUNET_free (controller); 1394 GNUNET_free (controller);
1374} 1395}
1375 1396
@@ -1384,7 +1405,7 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controll
1384 * will be invalid. Cannot be NULL. 1405 * will be invalid. Cannot be NULL.
1385 * @param cc_cls the closure for the cc 1406 * @param cc_cls the closure for the cc
1386 * @return handle to the host registration which can be used to cancel the 1407 * @return handle to the host registration which can be used to cancel the
1387 * registration 1408 * registration
1388 */ 1409 */
1389struct GNUNET_TESTBED_HostRegistrationHandle * 1410struct GNUNET_TESTBED_HostRegistrationHandle *
1390GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, 1411GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
@@ -1404,11 +1425,10 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
1404 hostname = GNUNET_TESTBED_host_get_hostname_ (host); 1425 hostname = GNUNET_TESTBED_host_get_hostname_ (host);
1405 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller)) 1426 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller))
1406 { 1427 {
1407 LOG (GNUNET_ERROR_TYPE_WARNING, 1428 LOG (GNUNET_ERROR_TYPE_WARNING, "Host hostname: %s already registered\n",
1408 "Host hostname: %s already registered\n",
1409 (NULL == hostname) ? "localhost" : hostname); 1429 (NULL == hostname) ? "localhost" : hostname);
1410 return NULL; 1430 return NULL;
1411 } 1431 }
1412 rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle)); 1432 rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle));
1413 rh->host = host; 1433 rh->host = host;
1414 rh->c = controller; 1434 rh->c = controller;
@@ -1436,7 +1456,8 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
1436 if (NULL != username) 1456 if (NULL != username)
1437 memcpy (&msg[1], username, user_name_length); 1457 memcpy (&msg[1], username, user_name_length);
1438 strcpy (((void *) &msg[1]) + user_name_length, hostname); 1458 strcpy (((void *) &msg[1]) + user_name_length, hostname);
1439 GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *) msg); 1459 GNUNET_TESTBED_queue_message_ (controller,
1460 (struct GNUNET_MessageHeader *) msg);
1440 return rh; 1461 return rh;
1441} 1462}
1442 1463
@@ -1458,7 +1479,7 @@ GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
1458 return; 1479 return;
1459 } 1480 }
1460 handle->c->rh = NULL; 1481 handle->c->rh = NULL;
1461 GNUNET_free (handle); 1482 GNUNET_free (handle);
1462} 1483}
1463 1484
1464 1485
@@ -1479,29 +1500,28 @@ GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
1479 */ 1500 */
1480struct GNUNET_TESTBED_Operation * 1501struct GNUNET_TESTBED_Operation *
1481GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master, 1502GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
1482 struct GNUNET_TESTBED_Host *delegated_host, 1503 struct GNUNET_TESTBED_Host *delegated_host,
1483 struct GNUNET_TESTBED_Host *slave_host, 1504 struct GNUNET_TESTBED_Host *slave_host,
1484 const char *sxcfg, 1505 const char *sxcfg, size_t sxcfg_size,
1485 size_t sxcfg_size, 1506 size_t scfg_size, int is_subordinate)
1486 size_t scfg_size,
1487 int is_subordinate)
1488{ 1507{
1489 struct OperationContext *opc; 1508 struct OperationContext *opc;
1490 struct GNUNET_TESTBED_ControllerLinkMessage *msg; 1509 struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1491 uint16_t msg_size; 1510 uint16_t msg_size;
1492 1511
1493 GNUNET_assert (GNUNET_YES == 1512 GNUNET_assert (GNUNET_YES ==
1494 GNUNET_TESTBED_is_host_registered_ (delegated_host, master)); 1513 GNUNET_TESTBED_is_host_registered_ (delegated_host, master));
1495 if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host))) 1514 if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host)))
1496 GNUNET_assert (GNUNET_YES == 1515 GNUNET_assert (GNUNET_YES ==
1497 GNUNET_TESTBED_is_host_registered_ (slave_host, master)); 1516 GNUNET_TESTBED_is_host_registered_ (slave_host, master));
1498 msg_size = sxcfg_size + sizeof (struct GNUNET_TESTBED_ControllerLinkMessage); 1517 msg_size = sxcfg_size + sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1499 msg = GNUNET_malloc (msg_size); 1518 msg = GNUNET_malloc (msg_size);
1500 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS); 1519 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS);
1501 msg->header.size = htons (msg_size); 1520 msg->header.size = htons (msg_size);
1502 msg->delegated_host_id = htonl (GNUNET_TESTBED_host_get_id_ (delegated_host)); 1521 msg->delegated_host_id = htonl (GNUNET_TESTBED_host_get_id_ (delegated_host));
1503 msg->slave_host_id = htonl (GNUNET_TESTBED_host_get_id_ 1522 msg->slave_host_id =
1504 ((NULL != slave_host) ? slave_host : master->host)); 1523 htonl (GNUNET_TESTBED_host_get_id_
1524 ((NULL != slave_host) ? slave_host : master->host));
1505 msg->config_size = htons ((uint16_t) scfg_size); 1525 msg->config_size = htons ((uint16_t) scfg_size);
1506 msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; 1526 msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0;
1507 memcpy (&msg[1], sxcfg, sxcfg_size); 1527 memcpy (&msg[1], sxcfg, sxcfg_size);
@@ -1512,8 +1532,9 @@ GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
1512 opc->id = master->operation_counter++; 1532 opc->id = master->operation_counter++;
1513 opc->state = OPC_STATE_INIT; 1533 opc->state = OPC_STATE_INIT;
1514 msg->operation_id = GNUNET_htonll (opc->id); 1534 msg->operation_id = GNUNET_htonll (opc->id);
1515 opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_link_controllers, 1535 opc->op =
1516 &oprelease_link_controllers); 1536 GNUNET_TESTBED_operation_create_ (opc, &opstart_link_controllers,
1537 &oprelease_link_controllers);
1517 GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations, 1538 GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations,
1518 opc->op); 1539 opc->op);
1519 return opc->op; 1540 return opc->op;
@@ -1526,24 +1547,24 @@ GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
1526 * @param config the serialized configuration 1547 * @param config the serialized configuration
1527 * @param size the size of config 1548 * @param size the size of config
1528 * @param xconfig will be set to the compressed configuration (memory is fresly 1549 * @param xconfig will be set to the compressed configuration (memory is fresly
1529 * allocated) 1550 * allocated)
1530 * @return the size of the xconfig 1551 * @return the size of the xconfig
1531 */ 1552 */
1532size_t 1553size_t
1533GNUNET_TESTBED_compress_config_ (const char *config, size_t size, 1554GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
1534 char **xconfig) 1555 char **xconfig)
1535{ 1556{
1536 size_t xsize; 1557 size_t xsize;
1537 1558
1538 xsize = compressBound ((uLong) size); 1559 xsize = compressBound ((uLong) size);
1539 *xconfig = GNUNET_malloc (xsize); 1560 *xconfig = GNUNET_malloc (xsize);
1540 GNUNET_assert (Z_OK == 1561 GNUNET_assert (Z_OK ==
1541 compress2 ((Bytef *)* xconfig, (uLongf *) &xsize, 1562 compress2 ((Bytef *) * xconfig, (uLongf *) & xsize,
1542 (const Bytef *) config, (uLongf) size, 1563 (const Bytef *) config, (uLongf) size,
1543 Z_BEST_SPEED)); 1564 Z_BEST_SPEED));
1544 return xsize; 1565 return xsize;
1545} 1566}
1546 1567
1547 1568
1548/** 1569/**
1549 * Create a link from slave controller to delegated controller. Whenever the 1570 * Create a link from slave controller to delegated controller. Whenever the
@@ -1559,7 +1580,7 @@ GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
1559 * 1580 *
1560 * @param master handle to the master controller who creates the association 1581 * @param master handle to the master controller who creates the association
1561 * @param delegated_host requests to which host should be delegated 1582 * @param delegated_host requests to which host should be delegated
1562 * @param slave_host which host is used to run the slave controller 1583 * @param slave_host which host is used to run the slave controller
1563 * @param slave_cfg configuration to use for the slave controller 1584 * @param slave_cfg configuration to use for the slave controller
1564 * @param is_subordinate GNUNET_YES if the slave should be started (and stopped) 1585 * @param is_subordinate GNUNET_YES if the slave should be started (and stopped)
1565 * by the master controller; GNUNET_NO if we are just 1586 * by the master controller; GNUNET_NO if we are just
@@ -1568,31 +1589,29 @@ GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
1568 */ 1589 */
1569struct GNUNET_TESTBED_Operation * 1590struct GNUNET_TESTBED_Operation *
1570GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, 1591GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
1571 struct GNUNET_TESTBED_Host *delegated_host, 1592 struct GNUNET_TESTBED_Host *delegated_host,
1572 struct GNUNET_TESTBED_Host *slave_host, 1593 struct GNUNET_TESTBED_Host *slave_host,
1573 const struct GNUNET_CONFIGURATION_Handle *slave_cfg, 1594 const struct GNUNET_CONFIGURATION_Handle
1574 int is_subordinate) 1595 *slave_cfg, int is_subordinate)
1575{ 1596{
1576 struct GNUNET_TESTBED_Operation *op; 1597 struct GNUNET_TESTBED_Operation *op;
1577 char *config; 1598 char *config;
1578 char *cconfig; 1599 char *cconfig;
1579 size_t cc_size; 1600 size_t cc_size;
1580 size_t config_size; 1601 size_t config_size;
1581 1602
1582 GNUNET_assert (GNUNET_YES == 1603 GNUNET_assert (GNUNET_YES ==
1583 GNUNET_TESTBED_is_host_registered_ (delegated_host, master)); 1604 GNUNET_TESTBED_is_host_registered_ (delegated_host, master));
1584 if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host))) 1605 if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host)))
1585 GNUNET_assert (GNUNET_YES == 1606 GNUNET_assert (GNUNET_YES ==
1586 GNUNET_TESTBED_is_host_registered_ (slave_host, master)); 1607 GNUNET_TESTBED_is_host_registered_ (slave_host, master));
1587 config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size); 1608 config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size);
1588 cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); 1609 cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig);
1589 GNUNET_free (config); 1610 GNUNET_free (config);
1590 GNUNET_assert ((UINT16_MAX - 1611 GNUNET_assert ((UINT16_MAX - sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) >= cc_size); /* Configuration doesn't fit in 1 message */
1591 sizeof (struct GNUNET_TESTBED_ControllerLinkMessage))
1592 >= cc_size); /* Configuration doesn't fit in 1 message */
1593 op = GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host, 1612 op = GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host,
1594 (const char *) cconfig, 1613 (const char *) cconfig, cc_size,
1595 cc_size, config_size, is_subordinate); 1614 config_size, is_subordinate);
1596 GNUNET_free (cconfig); 1615 GNUNET_free (cconfig);
1597 return op; 1616 return op;
1598} 1617}
@@ -1608,8 +1627,9 @@ GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
1608 * be written to. 1627 * be written to.
1609 */ 1628 */
1610void 1629void
1611GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller, 1630GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller
1612 const char *filename) 1631 *controller,
1632 const char *filename)
1613{ 1633{
1614 GNUNET_break (0); 1634 GNUNET_break (0);
1615} 1635}
@@ -1626,7 +1646,8 @@ GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller
1626 */ 1646 */
1627struct GNUNET_TESTBED_HelperInit * 1647struct GNUNET_TESTBED_HelperInit *
1628GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, 1648GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
1629 const struct GNUNET_CONFIGURATION_Handle *cfg) 1649 const struct GNUNET_CONFIGURATION_Handle
1650 *cfg)
1630{ 1651{
1631 struct GNUNET_TESTBED_HelperInit *msg; 1652 struct GNUNET_TESTBED_HelperInit *msg;
1632 char *config; 1653 char *config;
@@ -1639,13 +1660,13 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
1639 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); 1660 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
1640 GNUNET_assert (NULL != config); 1661 GNUNET_assert (NULL != config);
1641 xconfig_size = 1662 xconfig_size =
1642 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); 1663 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
1643 GNUNET_free (config); 1664 GNUNET_free (config);
1644 cname_len = strlen (cname); 1665 cname_len = strlen (cname);
1645 msg_size = xconfig_size + cname_len + 1 + 1666 msg_size =
1646 sizeof (struct GNUNET_TESTBED_HelperInit); 1667 xconfig_size + cname_len + 1 + sizeof (struct GNUNET_TESTBED_HelperInit);
1647 msg = GNUNET_realloc (xconfig, msg_size); 1668 msg = GNUNET_realloc (xconfig, msg_size);
1648 (void) memmove ( ((void *) &msg[1]) + cname_len + 1, msg, xconfig_size); 1669 (void) memmove (((void *) &msg[1]) + cname_len + 1, msg, xconfig_size);
1649 msg->header.size = htons (msg_size); 1670 msg->header.size = htons (msg_size);
1650 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT); 1671 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT);
1651 msg->cname_size = htons (cname_len); 1672 msg->cname_size = htons (cname_len);
@@ -1660,8 +1681,8 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
1660 * of the operation and will ensure that no event 1681 * of the operation and will ensure that no event
1661 * is generated for the operation. Does NOT guarantee 1682 * is generated for the operation. Does NOT guarantee
1662 * that the operation will be fully undone (or that 1683 * that the operation will be fully undone (or that
1663 * nothing ever happened). 1684 * nothing ever happened).
1664 * 1685 *
1665 * @param operation operation to cancel 1686 * @param operation operation to cancel
1666 */ 1687 */
1667void 1688void
@@ -1677,7 +1698,7 @@ GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation)
1677 * of type 'operation_finished' to fully remove the operation 1698 * of type 'operation_finished' to fully remove the operation
1678 * from the operation queue. After calling this function, the 1699 * from the operation queue. After calling this function, the
1679 * 'op_result' becomes invalid (!). 1700 * 'op_result' becomes invalid (!).
1680 * 1701 *
1681 * @param operation operation to signal completion for 1702 * @param operation operation to signal completion for
1682 */ 1703 */
1683void 1704void
@@ -1717,18 +1738,20 @@ GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct
1717 uLong config_size; 1738 uLong config_size;
1718 int ret; 1739 int ret;
1719 uint16_t msize; 1740 uint16_t msize;
1720 1741
1721 config_size = (uLong) ntohs (msg->config_size); 1742 config_size = (uLong) ntohs (msg->config_size);
1722 config = GNUNET_malloc (config_size); 1743 config = GNUNET_malloc (config_size);
1723 msize = ntohs (msg->header.size); 1744 msize = ntohs (msg->header.size);
1724 msize -= sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage); 1745 msize -= sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1725 if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size, 1746 if (Z_OK !=
1726 (const Bytef *) &msg[1], (uLong) msize))) 1747 (ret =
1748 uncompress ((Bytef *) config, &config_size, (const Bytef *) &msg[1],
1749 (uLong) msize)))
1727 GNUNET_assert (0); 1750 GNUNET_assert (0);
1728 cfg = GNUNET_CONFIGURATION_create (); 1751 cfg = GNUNET_CONFIGURATION_create ();
1729 GNUNET_assert (GNUNET_OK == 1752 GNUNET_assert (GNUNET_OK ==
1730 GNUNET_CONFIGURATION_deserialize (cfg, config, 1753 GNUNET_CONFIGURATION_deserialize (cfg, config,
1731 (size_t) config_size, 1754 (size_t) config_size,
1732 GNUNET_NO)); 1755 GNUNET_NO));
1733 GNUNET_free (config); 1756 GNUNET_free (config);
1734 return cfg; 1757 return cfg;