aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet-service-testbed.c')
-rw-r--r--src/testbed/gnunet-service-testbed.c801
1 files changed, 390 insertions, 411 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 560740315..9abf6bfd5 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -79,7 +79,7 @@ struct Context
79 * The TESTING system handle for starting peers locally 79 * The TESTING system handle for starting peers locally
80 */ 80 */
81 struct GNUNET_TESTING_System *system; 81 struct GNUNET_TESTING_System *system;
82 82
83 /** 83 /**
84 * Event mask of event to be responded in this context 84 * Event mask of event to be responded in this context
85 */ 85 */
@@ -106,12 +106,12 @@ struct MessageQueue
106 * The client to send the message to 106 * The client to send the message to
107 */ 107 */
108 struct GNUNET_SERVER_Client *client; 108 struct GNUNET_SERVER_Client *client;
109 109
110 /** 110 /**
111 * next pointer for DLL 111 * next pointer for DLL
112 */ 112 */
113 struct MessageQueue *next; 113 struct MessageQueue *next;
114 114
115 /** 115 /**
116 * prev pointer for DLL 116 * prev pointer for DLL
117 */ 117 */
@@ -184,28 +184,27 @@ struct Slave
184 * States of LCFContext 184 * States of LCFContext
185 */ 185 */
186enum LCFContextState 186enum LCFContextState
187 { 187{
188 /** 188 /**
189 * The Context has been initialized; Nothing has been done on it 189 * The Context has been initialized; Nothing has been done on it
190 */ 190 */
191 INIT, 191 INIT,
192 192
193 /** 193 /**
194 * Delegated host has been registered at the forwarding controller 194 * Delegated host has been registered at the forwarding controller
195 */ 195 */
196 DELEGATED_HOST_REGISTERED, 196 DELEGATED_HOST_REGISTERED,
197 197
198 /** 198 /**
199 * The slave host has been registred at the forwarding controller 199 * The slave host has been registred at the forwarding controller
200 */ 200 */
201 SLAVE_HOST_REGISTERED, 201 SLAVE_HOST_REGISTERED,
202 202
203 /** 203 /**
204 * The context has been finished (may have error) 204 * The context has been finished (may have error)
205 */ 205 */
206 FINISHED 206 FINISHED
207 207};
208 };
209 208
210 209
211/** 210/**
@@ -285,13 +284,13 @@ struct Peer
285{ 284{
286 union 285 union
287 { 286 {
288 struct 287 struct
289 { 288 {
290 /** 289 /**
291 * The peer handle from testing API 290 * The peer handle from testing API
292 */ 291 */
293 struct GNUNET_TESTING_Peer *peer; 292 struct GNUNET_TESTING_Peer *peer;
294 293
295 /** 294 /**
296 * The modified (by GNUNET_TESTING_peer_configure) configuration this 295 * The modified (by GNUNET_TESTING_peer_configure) configuration this
297 * peer is configured with 296 * peer is configured with
@@ -308,7 +307,7 @@ struct Peer
308 struct GNUNET_TESTBED_Controller *controller; 307 struct GNUNET_TESTBED_Controller *controller;
309 308
310 } remote; 309 } remote;
311 310
312 } details; 311 } details;
313 312
314 /** 313 /**
@@ -328,23 +327,23 @@ struct Peer
328 * State information for overlay connect context 327 * State information for overlay connect context
329 */ 328 */
330enum OCCState 329enum OCCState
331 { 330{
332 /** 331 /**
333 * Initial state 332 * Initial state
334 */ 333 */
335 OCC_STATE_INIT, 334 OCC_STATE_INIT,
336 335
337 /** 336 /**
338 * Peer 1 has connected to peer0 337 * Peer 1 has connected to peer0
339 */ 338 */
340 OCC_STATE_PEER0_SUCCESS, 339 OCC_STATE_PEER0_SUCCESS,
341 340
342 /** 341 /**
343 * Peer 2 has connected to peer1 342 * Peer 2 has connected to peer1
344 */ 343 */
345 OCC_STATE_PEER1_SUCCESS, 344 OCC_STATE_PEER1_SUCCESS,
346 345
347 }; 346};
348 347
349 348
350/** 349/**
@@ -366,7 +365,7 @@ struct OverlayConnectContext
366 * The other peer 365 * The other peer
367 */ 366 */
368 struct Peer *other_peer; 367 struct Peer *other_peer;
369 368
370 /** 369 /**
371 * Transport handle of the first peer to offer second peer's HELLO 370 * Transport handle of the first peer to offer second peer's HELLO
372 */ 371 */
@@ -386,7 +385,7 @@ struct OverlayConnectContext
386 * HELLO of the other peer 385 * HELLO of the other peer
387 */ 386 */
388 struct GNUNET_MessageHeader *hello; 387 struct GNUNET_MessageHeader *hello;
389 388
390 /** 389 /**
391 * Get hello handle for the other peer 390 * Get hello handle for the other peer
392 */ 391 */
@@ -396,7 +395,7 @@ struct OverlayConnectContext
396 * The error message we send if this overlay connect operation has timed out 395 * The error message we send if this overlay connect operation has timed out
397 */ 396 */
398 char *emsg; 397 char *emsg;
399 398
400 /** 399 /**
401 * The peer identity of the first peer 400 * The peer identity of the first peer
402 */ 401 */
@@ -417,7 +416,7 @@ struct OverlayConnectContext
417 * connect to peer 2 416 * connect to peer 2
418 */ 417 */
419 GNUNET_SCHEDULER_TaskIdentifier send_hello_task; 418 GNUNET_SCHEDULER_TaskIdentifier send_hello_task;
420 419
421 /** 420 /**
422 * The id of the overlay connect timeout task 421 * The id of the overlay connect timeout task
423 */ 422 */
@@ -450,7 +449,7 @@ struct ForwardedOperationContext
450 /** 449 /**
451 * Closure pointer 450 * Closure pointer
452 */ 451 */
453 void *cls; 452 void *cls;
454 453
455 /** 454 /**
456 * Task ID for the timeout task 455 * Task ID for the timeout task
@@ -460,7 +459,7 @@ struct ForwardedOperationContext
460 /** 459 /**
461 * The id of the operation that has been forwarded 460 * The id of the operation that has been forwarded
462 */ 461 */
463 uint64_t operation_id; 462 uint64_t operation_id;
464 463
465}; 464};
466 465
@@ -479,7 +478,7 @@ struct LinkControllersContext
479 * The ID of the operation 478 * The ID of the operation
480 */ 479 */
481 uint64_t operation_id; 480 uint64_t operation_id;
482 481
483 /** 482 /**
484 * Pointer to the slave handle if we are directly starting/connecting to the controller 483 * Pointer to the slave handle if we are directly starting/connecting to the controller
485 */ 484 */
@@ -614,11 +613,11 @@ transmit_ready_notify (void *cls, size_t size, void *buf)
614 GNUNET_free (mq_entry); 613 GNUNET_free (mq_entry);
615 mq_entry = mq_head; 614 mq_entry = mq_head;
616 if (NULL != mq_entry) 615 if (NULL != mq_entry)
617 transmit_handle = 616 transmit_handle =
618 GNUNET_SERVER_notify_transmit_ready (mq_entry->client, 617 GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
619 ntohs (mq_entry->msg->size), 618 ntohs (mq_entry->msg->size),
620 GNUNET_TIME_UNIT_FOREVER_REL, 619 GNUNET_TIME_UNIT_FOREVER_REL,
621 &transmit_ready_notify, NULL); 620 &transmit_ready_notify, NULL);
622 return size; 621 return size;
623} 622}
624 623
@@ -640,18 +639,18 @@ queue_message (struct GNUNET_SERVER_Client *client,
640 type = ntohs (msg->type); 639 type = ntohs (msg->type);
641 size = ntohs (msg->size); 640 size = ntohs (msg->size);
642 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && 641 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
643 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); 642 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
644 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue)); 643 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
645 mq_entry->msg = msg; 644 mq_entry->msg = msg;
646 mq_entry->client = client; 645 mq_entry->client = client;
647 LOG_DEBUG ( "Queueing message of type %u, size %u for sending\n", type, 646 LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type,
648 ntohs (msg->size)); 647 ntohs (msg->size));
649 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry); 648 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
650 if (NULL == transmit_handle) 649 if (NULL == transmit_handle)
651 transmit_handle = 650 transmit_handle =
652 GNUNET_SERVER_notify_transmit_ready (client, size, 651 GNUNET_SERVER_notify_transmit_ready (client, size,
653 GNUNET_TIME_UNIT_FOREVER_REL, 652 GNUNET_TIME_UNIT_FOREVER_REL,
654 &transmit_ready_notify, NULL); 653 &transmit_ready_notify, NULL);
655} 654}
656 655
657 656
@@ -676,7 +675,7 @@ TESTBED_realloc (void *ptr, size_t size, size_t new_size)
676/** 675/**
677 * Function to add a host to the current list of known hosts 676 * Function to add a host to the current list of known hosts
678 * 677 *
679 * @param host the host to add 678 * @param host the host to add
680 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id 679 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
681 * already in use 680 * already in use
682 */ 681 */
@@ -688,11 +687,11 @@ host_list_add (struct GNUNET_TESTBED_Host *host)
688 host_id = GNUNET_TESTBED_host_get_id_ (host); 687 host_id = GNUNET_TESTBED_host_get_id_ (host);
689 if (host_list_size <= host_id) 688 if (host_list_size <= host_id)
690 { 689 {
691 host_list = 690 host_list =
692 TESTBED_realloc (host_list, 691 TESTBED_realloc (host_list,
693 sizeof (struct GNUNET_TESTBED_Host *) * host_list_size, 692 sizeof (struct GNUNET_TESTBED_Host *) * host_list_size,
694 sizeof (struct GNUNET_TESTBED_Host *) * 693 sizeof (struct GNUNET_TESTBED_Host *) *
695 (host_list_size + LIST_GROW_STEP)); 694 (host_list_size + LIST_GROW_STEP));
696 host_list_size += LIST_GROW_STEP; 695 host_list_size += LIST_GROW_STEP;
697 } 696 }
698 if (NULL != host_list[host_id]) 697 if (NULL != host_list[host_id])
@@ -715,11 +714,10 @@ route_list_add (struct Route *route)
715{ 714{
716 if (route->dest >= route_list_size) 715 if (route->dest >= route_list_size)
717 { 716 {
718 route_list = 717 route_list =
719 TESTBED_realloc (route_list, 718 TESTBED_realloc (route_list, sizeof (struct Route *) * route_list_size,
720 sizeof (struct Route *) * route_list_size, 719 sizeof (struct Route *) * (route_list_size +
721 sizeof (struct Route *) * 720 LIST_GROW_STEP));
722 (route_list_size + LIST_GROW_STEP));
723 route_list_size += LIST_GROW_STEP; 721 route_list_size += LIST_GROW_STEP;
724 } 722 }
725 GNUNET_assert (NULL == route_list[route->dest]); 723 GNUNET_assert (NULL == route_list[route->dest]);
@@ -735,12 +733,12 @@ route_list_add (struct Route *route)
735static void 733static void
736slave_list_add (struct Slave *slave) 734slave_list_add (struct Slave *slave)
737{ 735{
738 if (slave->host_id >= slave_list_size) 736 if (slave->host_id >= slave_list_size)
739 { 737 {
740 slave_list = TESTBED_realloc (slave_list, 738 slave_list =
741 sizeof (struct Slave *) *slave_list_size, 739 TESTBED_realloc (slave_list, sizeof (struct Slave *) * slave_list_size,
742 sizeof (struct Slave *) * 740 sizeof (struct Slave *) * (slave_list_size +
743 (slave_list_size + LIST_GROW_STEP)); 741 LIST_GROW_STEP));
744 slave_list_size += LIST_GROW_STEP; 742 slave_list_size += LIST_GROW_STEP;
745 } 743 }
746 GNUNET_assert (NULL == slave_list[slave->host_id]); 744 GNUNET_assert (NULL == slave_list[slave->host_id]);
@@ -757,15 +755,15 @@ static void
757peer_list_add (struct Peer *peer) 755peer_list_add (struct Peer *peer)
758{ 756{
759 uint32_t orig_size; 757 uint32_t orig_size;
760 758
761 orig_size = peer_list_size; 759 orig_size = peer_list_size;
762 if (peer->id >= peer_list_size) 760 if (peer->id >= peer_list_size)
763 { 761 {
764 while (peer->id >= peer_list_size) 762 while (peer->id >= peer_list_size)
765 peer_list_size += LIST_GROW_STEP; 763 peer_list_size += LIST_GROW_STEP;
766 peer_list = TESTBED_realloc (peer_list, 764 peer_list =
767 sizeof (struct Peer *) * orig_size, 765 TESTBED_realloc (peer_list, sizeof (struct Peer *) * orig_size,
768 sizeof (struct Peer *) * peer_list_size); 766 sizeof (struct Peer *) * peer_list_size);
769 } 767 }
770 GNUNET_assert (NULL == peer_list[peer->id]); 768 GNUNET_assert (NULL == peer_list[peer->id]);
771 peer_list[peer->id] = peer; 769 peer_list[peer->id] = peer;
@@ -797,8 +795,8 @@ peer_list_remove (struct Peer *peer)
797 } 795 }
798 if (orig_size == peer_list_size) 796 if (orig_size == peer_list_size)
799 return; 797 return;
800 peer_list = GNUNET_realloc (peer_list, sizeof (struct Peer *) 798 peer_list =
801 * peer_list_size); 799 GNUNET_realloc (peer_list, sizeof (struct Peer *) * peer_list_size);
802} 800}
803 801
804 802
@@ -814,8 +812,8 @@ static struct Route *
814find_dest_route (uint32_t host_id) 812find_dest_route (uint32_t host_id)
815{ 813{
816 struct Route *route; 814 struct Route *route;
817 815
818 while(NULL != (route = route_list[host_id])) 816 while (NULL != (route = route_list[host_id]))
819 { 817 {
820 if (route->thru == master_context->host_id) 818 if (route->thru == master_context->host_id)
821 break; 819 break;
@@ -847,14 +845,13 @@ route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
847 */ 845 */
848static void 846static void
849send_operation_fail_msg (struct GNUNET_SERVER_Client *client, 847send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
850 uint64_t operation_id, 848 uint64_t operation_id, const char *emsg)
851 const char *emsg)
852{ 849{
853 struct GNUNET_TESTBED_OperationFailureEventMessage *msg; 850 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
854 uint16_t msize; 851 uint16_t msize;
855 uint16_t emsg_len; 852 uint16_t emsg_len;
856 853
857 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage); 854 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
858 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; 855 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
859 msize += emsg_len; 856 msize += emsg_len;
860 msg = GNUNET_malloc (msize); 857 msg = GNUNET_malloc (msize);
@@ -876,18 +873,18 @@ send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
876 */ 873 */
877static void 874static void
878send_operation_success_msg (struct GNUNET_SERVER_Client *client, 875send_operation_success_msg (struct GNUNET_SERVER_Client *client,
879 uint64_t operation_id) 876 uint64_t operation_id)
880{ 877{
881 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; 878 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
882 uint16_t msize; 879 uint16_t msize;
883 880
884 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage); 881 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
885 msg = GNUNET_malloc (msize); 882 msg = GNUNET_malloc (msize);
886 msg->header.size = htons (msize); 883 msg->header.size = htons (msize);
887 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS); 884 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
888 msg->operation_id = GNUNET_htonll (operation_id); 885 msg->operation_id = GNUNET_htonll (operation_id);
889 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); 886 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
890 queue_message (client, &msg->header); 887 queue_message (client, &msg->header);
891} 888}
892 889
893 890
@@ -923,19 +920,19 @@ lcf_proc_cc (void *cls, const char *emsg)
923 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); 920 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
924 break; 921 break;
925 case DELEGATED_HOST_REGISTERED: 922 case DELEGATED_HOST_REGISTERED:
926 if (NULL != emsg) 923 if (NULL != emsg)
927 goto registration_error; 924 goto registration_error;
928 lcf->state = SLAVE_HOST_REGISTERED; 925 lcf->state = SLAVE_HOST_REGISTERED;
929 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); 926 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
930 break; 927 break;
931 default: 928 default:
932 GNUNET_assert (0); /* Shouldn't reach here */ 929 GNUNET_assert (0); /* Shouldn't reach here */
933 } 930 }
934 return; 931 return;
935 932
936 registration_error: 933registration_error:
937 LOG (GNUNET_ERROR_TYPE_WARNING, 934 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
938 "Host registration failed with message: %s\n", emsg); 935 emsg);
939 lcf->state = FINISHED; 936 lcf->state = FINISHED;
940 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); 937 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
941} 938}
@@ -953,15 +950,15 @@ forwarded_operation_reply_relay (void *cls,
953 const struct GNUNET_MessageHeader *msg) 950 const struct GNUNET_MessageHeader *msg)
954{ 951{
955 struct ForwardedOperationContext *fopc = cls; 952 struct ForwardedOperationContext *fopc = cls;
956 struct GNUNET_MessageHeader *dup_msg; 953 struct GNUNET_MessageHeader *dup_msg;
957 uint16_t msize; 954 uint16_t msize;
958 955
959 msize = ntohs (msg->size); 956 msize = ntohs (msg->size);
960 dup_msg = GNUNET_malloc (msize); 957 dup_msg = GNUNET_malloc (msize);
961 (void) memcpy (dup_msg, msg, msize); 958 (void) memcpy (dup_msg, msg, msize);
962 queue_message (fopc->client, dup_msg); 959 queue_message (fopc->client, dup_msg);
963 GNUNET_SERVER_client_drop (fopc->client); 960 GNUNET_SERVER_client_drop (fopc->client);
964 GNUNET_SCHEDULER_cancel (fopc->timeout_task); 961 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
965 GNUNET_free (fopc); 962 GNUNET_free (fopc);
966} 963}
967 964
@@ -974,15 +971,14 @@ forwarded_operation_reply_relay (void *cls,
974 */ 971 */
975static void 972static void
976forwarded_operation_timeout (void *cls, 973forwarded_operation_timeout (void *cls,
977 const struct GNUNET_SCHEDULER_TaskContext 974 const struct GNUNET_SCHEDULER_TaskContext *tc)
978 *tc)
979{ 975{
980 struct ForwardedOperationContext *fopc = cls; 976 struct ForwardedOperationContext *fopc = cls;
981 977
982 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); 978 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
983 send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout"); 979 send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
984 GNUNET_SERVER_client_drop (fopc->client); 980 GNUNET_SERVER_client_drop (fopc->client);
985 GNUNET_free (fopc); 981 GNUNET_free (fopc);
986} 982}
987 983
988 984
@@ -998,19 +994,19 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
998 struct LCFContext *lcf = cls; 994 struct LCFContext *lcf = cls;
999 struct LCFContextQueue *lcfq; 995 struct LCFContextQueue *lcfq;
1000 struct ForwardedOperationContext *fopc; 996 struct ForwardedOperationContext *fopc;
1001 997
1002 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK; 998 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
1003 switch (lcf->state) 999 switch (lcf->state)
1004 { 1000 {
1005 case INIT: 1001 case INIT:
1006 if (GNUNET_NO == 1002 if (GNUNET_NO ==
1007 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id], 1003 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id],
1008 lcf->gateway->controller)) 1004 lcf->gateway->controller))
1009 { 1005 {
1010 lcf->rhandle = 1006 lcf->rhandle =
1011 GNUNET_TESTBED_register_host (lcf->gateway->controller, 1007 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1012 host_list[lcf->delegated_host_id], 1008 host_list[lcf->delegated_host_id],
1013 lcf_proc_cc, lcf); 1009 lcf_proc_cc, lcf);
1014 } 1010 }
1015 else 1011 else
1016 { 1012 {
@@ -1020,13 +1016,13 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1020 break; 1016 break;
1021 case DELEGATED_HOST_REGISTERED: 1017 case DELEGATED_HOST_REGISTERED:
1022 if (GNUNET_NO == 1018 if (GNUNET_NO ==
1023 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id], 1019 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id],
1024 lcf->gateway->controller)) 1020 lcf->gateway->controller))
1025 { 1021 {
1026 lcf->rhandle = 1022 lcf->rhandle =
1027 GNUNET_TESTBED_register_host (lcf->gateway->controller, 1023 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1028 host_list[lcf->slave_host_id], 1024 host_list[lcf->slave_host_id],
1029 lcf_proc_cc, lcf); 1025 lcf_proc_cc, lcf);
1030 } 1026 }
1031 else 1027 else
1032 { 1028 {
@@ -1038,15 +1034,15 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1038 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); 1034 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1039 fopc->client = lcf->client; 1035 fopc->client = lcf->client;
1040 fopc->operation_id = lcf->operation_id; 1036 fopc->operation_id = lcf->operation_id;
1041 fopc->opc = 1037 fopc->opc =
1042 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller, 1038 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
1043 lcf->operation_id, 1039 lcf->operation_id,
1044 &lcf->msg->header, 1040 &lcf->msg->header,
1045 &forwarded_operation_reply_relay, 1041 &forwarded_operation_reply_relay,
1046 fopc); 1042 fopc);
1047 fopc->timeout_task = 1043 fopc->timeout_task =
1048 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 1044 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1049 &forwarded_operation_timeout, fopc); 1045 fopc);
1050 lcf->state = FINISHED; 1046 lcf->state = FINISHED;
1051 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); 1047 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1052 break; 1048 break;
@@ -1058,8 +1054,8 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1058 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); 1054 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
1059 GNUNET_free (lcfq); 1055 GNUNET_free (lcfq);
1060 if (NULL != lcfq_head) 1056 if (NULL != lcfq_head)
1061 lcf_proc_task_id = 1057 lcf_proc_task_id =
1062 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf); 1058 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
1063 } 1059 }
1064} 1060}
1065 1061
@@ -1070,9 +1066,9 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1070 * @param cls struct Slave * 1066 * @param cls struct Slave *
1071 * @param event information about the event 1067 * @param event information about the event
1072 */ 1068 */
1073static void 1069static void
1074slave_event_callback (void *cls, 1070slave_event_callback (void *cls,
1075 const struct GNUNET_TESTBED_EventInformation *event) 1071 const struct GNUNET_TESTBED_EventInformation *event)
1076{ 1072{
1077 GNUNET_break (0); 1073 GNUNET_break (0);
1078} 1074}
@@ -1087,9 +1083,8 @@ slave_event_callback (void *cls,
1087 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, 1083 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
1088 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 1084 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1089 */ 1085 */
1090static void 1086static void
1091slave_status_callback (void *cls, 1087slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
1092 const struct GNUNET_CONFIGURATION_Handle *cfg,
1093 int status) 1088 int status)
1094{ 1089{
1095 struct LinkControllersContext *lcc = cls; 1090 struct LinkControllersContext *lcc = cls;
@@ -1097,20 +1092,19 @@ slave_status_callback (void *cls,
1097 if (GNUNET_SYSERR == status) 1092 if (GNUNET_SYSERR == status)
1098 { 1093 {
1099 lcc->slave->controller_proc = NULL; 1094 lcc->slave->controller_proc = NULL;
1100 LOG (GNUNET_ERROR_TYPE_WARNING, 1095 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
1101 "Unexpected slave shutdown\n"); 1096 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
1102 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
1103 return; 1097 return;
1104 } 1098 }
1105 lcc->slave->controller = 1099 lcc->slave->controller =
1106 GNUNET_TESTBED_controller_connect (cfg, host_list[lcc->slave->host_id], 1100 GNUNET_TESTBED_controller_connect (cfg, host_list[lcc->slave->host_id],
1107 master_context->event_mask, 1101 master_context->event_mask,
1108 &slave_event_callback, lcc->slave); 1102 &slave_event_callback, lcc->slave);
1109 if (NULL != lcc->slave->controller) 1103 if (NULL != lcc->slave->controller)
1110 send_operation_success_msg (lcc->client, lcc->operation_id); 1104 send_operation_success_msg (lcc->client, lcc->operation_id);
1111 else 1105 else
1112 send_operation_fail_msg (lcc->client, lcc->operation_id, 1106 send_operation_fail_msg (lcc->client, lcc->operation_id,
1113 "Could not connect to delegated controller"); 1107 "Could not connect to delegated controller");
1114 GNUNET_SERVER_client_drop (lcc->client); 1108 GNUNET_SERVER_client_drop (lcc->client);
1115 GNUNET_free (lcc); 1109 GNUNET_free (lcc);
1116} 1110}
@@ -1123,9 +1117,8 @@ slave_status_callback (void *cls,
1123 * @param client identification of the client 1117 * @param client identification of the client
1124 * @param message the actual message 1118 * @param message the actual message
1125 */ 1119 */
1126static void 1120static void
1127handle_init (void *cls, 1121handle_init (void *cls, struct GNUNET_SERVER_Client *client,
1128 struct GNUNET_SERVER_Client *client,
1129 const struct GNUNET_MessageHeader *message) 1122 const struct GNUNET_MessageHeader *message)
1130{ 1123{
1131 const struct GNUNET_TESTBED_InitMessage *msg; 1124 const struct GNUNET_TESTBED_InitMessage *msg;
@@ -1147,23 +1140,24 @@ handle_init (void *cls,
1147 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1140 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1148 return; 1141 return;
1149 } 1142 }
1150 msize -= sizeof (struct GNUNET_TESTBED_InitMessage); 1143 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
1151 controller_hostname = (const char *) &msg[1]; 1144 controller_hostname = (const char *) &msg[1];
1152 if ('\0' != controller_hostname[msize - 1]) 1145 if ('\0' != controller_hostname[msize - 1])
1153 { 1146 {
1154 GNUNET_break (0); 1147 GNUNET_break (0);
1155 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1148 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1156 return; 1149 return;
1157 } 1150 }
1158 master_context = GNUNET_malloc (sizeof (struct Context)); 1151 master_context = GNUNET_malloc (sizeof (struct Context));
1159 master_context->client = client; 1152 master_context->client = client;
1160 master_context->host_id = ntohl (msg->host_id); 1153 master_context->host_id = ntohl (msg->host_id);
1161 master_context->master_ip = GNUNET_strdup (controller_hostname); 1154 master_context->master_ip = GNUNET_strdup (controller_hostname);
1162 LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip); 1155 LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip);
1163 master_context->system = 1156 master_context->system =
1164 GNUNET_TESTING_system_create ("testbed", master_context->master_ip); 1157 GNUNET_TESTING_system_create ("testbed", master_context->master_ip);
1165 host = GNUNET_TESTBED_host_create_with_id (master_context->host_id, 1158 host =
1166 NULL, NULL, 0); 1159 GNUNET_TESTBED_host_create_with_id (master_context->host_id, NULL, NULL,
1160 0);
1167 host_list_add (host); 1161 host_list_add (host);
1168 master_context->event_mask = GNUNET_ntohll (msg->event_mask); 1162 master_context->event_mask = GNUNET_ntohll (msg->event_mask);
1169 GNUNET_SERVER_client_keep (client); 1163 GNUNET_SERVER_client_keep (client);
@@ -1180,9 +1174,8 @@ handle_init (void *cls,
1180 * @param client identification of the client 1174 * @param client identification of the client
1181 * @param message the actual message 1175 * @param message the actual message
1182 */ 1176 */
1183static void 1177static void
1184handle_add_host (void *cls, 1178handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
1185 struct GNUNET_SERVER_Client *client,
1186 const struct GNUNET_MessageHeader *message) 1179 const struct GNUNET_MessageHeader *message)
1187{ 1180{
1188 struct GNUNET_TESTBED_Host *host; 1181 struct GNUNET_TESTBED_Host *host;
@@ -1196,39 +1189,41 @@ handle_add_host (void *cls,
1196 uint16_t hostname_length; 1189 uint16_t hostname_length;
1197 uint16_t reply_size; 1190 uint16_t reply_size;
1198 uint16_t msize; 1191 uint16_t msize;
1199 1192
1200 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message; 1193 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
1201 msize = ntohs (msg->header.size); 1194 msize = ntohs (msg->header.size);
1202 username = (char *) &(msg[1]); 1195 username = (char *) &(msg[1]);
1203 username_length = ntohs (msg->user_name_length); 1196 username_length = ntohs (msg->user_name_length);
1204 GNUNET_assert (msize > (sizeof (struct GNUNET_TESTBED_AddHostMessage) 1197 GNUNET_assert (msize > (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length + 1)); /* msg must contain hostname */
1205 + username_length + 1)); /* msg must contain hostname */
1206 if (0 != username_length) 1198 if (0 != username_length)
1207 GNUNET_assert ('\0' == username[username_length]); 1199 GNUNET_assert ('\0' == username[username_length]);
1208 username_length = (0 == username_length) ? 0 : username_length + 1; 1200 username_length = (0 == username_length) ? 0 : username_length + 1;
1209 hostname = username + username_length; 1201 hostname = username + username_length;
1210 hostname_length = msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) 1202 hostname_length =
1211 + username_length); 1203 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
1212 GNUNET_assert ('\0' == hostname[hostname_length - 1]); 1204 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
1213 GNUNET_assert (strlen (hostname) == hostname_length - 1); 1205 GNUNET_assert (strlen (hostname) == hostname_length - 1);
1214 host_id = ntohl (msg->host_id); 1206 host_id = ntohl (msg->host_id);
1215 LOG_DEBUG ("Received ADDHOST message\n"); 1207 LOG_DEBUG ("Received ADDHOST message\n");
1216 LOG_DEBUG ("-------host id: %u\n", host_id); 1208 LOG_DEBUG ("-------host id: %u\n", host_id);
1217 if (NULL != hostname) LOG_DEBUG ("-------hostname: %s\n", hostname); 1209 if (NULL != hostname)
1218 if (0 != username_length) LOG_DEBUG ("-------username: %s\n", username); 1210 LOG_DEBUG ("-------hostname: %s\n", hostname);
1219 else 1211 if (0 != username_length)
1212 LOG_DEBUG ("-------username: %s\n", username);
1213 else
1220 { 1214 {
1221 LOG_DEBUG ("-------username: NULL\n"); 1215 LOG_DEBUG ("-------username: NULL\n");
1222 username = NULL; 1216 username = NULL;
1223 } 1217 }
1224 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); 1218 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1225 host = GNUNET_TESTBED_host_create_with_id (host_id, hostname, username, 1219 host =
1226 ntohs (msg->ssh_port)); 1220 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1221 ntohs (msg->ssh_port));
1227 GNUNET_assert (NULL != host); 1222 GNUNET_assert (NULL != host);
1228 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1223 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1229 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage); 1224 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1230 if (GNUNET_OK != host_list_add (host)) 1225 if (GNUNET_OK != host_list_add (host))
1231 { 1226 {
1232 /* We are unable to add a host */ 1227 /* We are unable to add a host */
1233 emsg = "A host exists with given host-id"; 1228 emsg = "A host exists with given host-id";
1234 LOG_DEBUG ("%s: %u", emsg, host_id); 1229 LOG_DEBUG ("%s: %u", emsg, host_id);
@@ -1238,10 +1233,10 @@ handle_add_host (void *cls,
1238 memcpy (&reply[1], emsg, strlen (emsg) + 1); 1233 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1239 } 1234 }
1240 else 1235 else
1241 reply = GNUNET_malloc (reply_size); 1236 reply = GNUNET_malloc (reply_size);
1242 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM); 1237 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
1243 reply->header.size = htons (reply_size); 1238 reply->header.size = htons (reply_size);
1244 reply->host_id = htonl (host_id); 1239 reply->host_id = htonl (host_id);
1245 queue_message (client, &reply->header); 1240 queue_message (client, &reply->header);
1246} 1241}
1247 1242
@@ -1256,9 +1251,8 @@ handle_add_host (void *cls,
1256 * iterate, 1251 * iterate,
1257 * GNUNET_NO if not. 1252 * GNUNET_NO if not.
1258 */ 1253 */
1259int ss_exists_iterator (void *cls, 1254int
1260 const struct GNUNET_HashCode * key, 1255ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1261 void *value)
1262{ 1256{
1263 struct SharedService *queried_ss = cls; 1257 struct SharedService *queried_ss = cls;
1264 struct SharedService *ss = value; 1258 struct SharedService *ss = value;
@@ -1277,9 +1271,8 @@ int ss_exists_iterator (void *cls,
1277 * @param client identification of the client 1271 * @param client identification of the client
1278 * @param message the actual message 1272 * @param message the actual message
1279 */ 1273 */
1280static void 1274static void
1281handle_configure_shared_service (void *cls, 1275handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1282 struct GNUNET_SERVER_Client *client,
1283 const struct GNUNET_MessageHeader *message) 1276 const struct GNUNET_MessageHeader *message)
1284{ 1277{
1285 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg; 1278 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
@@ -1288,7 +1281,7 @@ handle_configure_shared_service (void *cls,
1288 struct GNUNET_HashCode hash; 1281 struct GNUNET_HashCode hash;
1289 uint16_t msg_size; 1282 uint16_t msg_size;
1290 uint16_t service_name_size; 1283 uint16_t service_name_size;
1291 1284
1292 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message; 1285 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1293 msg_size = ntohs (message->size); 1286 msg_size = ntohs (message->size);
1294 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage)) 1287 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
@@ -1297,8 +1290,8 @@ handle_configure_shared_service (void *cls,
1297 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1290 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1298 return; 1291 return;
1299 } 1292 }
1300 service_name_size = msg_size - 1293 service_name_size =
1301 sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage); 1294 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1302 service_name = (char *) &msg[1]; 1295 service_name = (char *) &msg[1];
1303 if ('\0' != service_name[service_name_size - 1]) 1296 if ('\0' != service_name[service_name_size - 1])
1304 { 1297 {
@@ -1319,7 +1312,7 @@ handle_configure_shared_service (void *cls,
1319 ss->name = strdup (service_name); 1312 ss->name = strdup (service_name);
1320 ss->num_shared = ntohl (msg->num_peers); 1313 ss->num_shared = ntohl (msg->num_peers);
1321 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash); 1314 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1322 if (GNUNET_SYSERR == 1315 if (GNUNET_SYSERR ==
1323 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash, 1316 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1324 &ss_exists_iterator, ss)) 1317 &ss_exists_iterator, ss))
1325 { 1318 {
@@ -1331,7 +1324,7 @@ handle_configure_shared_service (void *cls,
1331 return; 1324 return;
1332 } 1325 }
1333 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss, 1326 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1334 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1327 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1335} 1328}
1336 1329
1337 1330
@@ -1342,9 +1335,8 @@ handle_configure_shared_service (void *cls,
1342 * @param client identification of the client 1335 * @param client identification of the client
1343 * @param message the actual message 1336 * @param message the actual message
1344 */ 1337 */
1345static void 1338static void
1346handle_link_controllers (void *cls, 1339handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1347 struct GNUNET_SERVER_Client *client,
1348 const struct GNUNET_MessageHeader *message) 1340 const struct GNUNET_MessageHeader *message)
1349{ 1341{
1350 const struct GNUNET_TESTBED_ControllerLinkMessage *msg; 1342 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
@@ -1352,13 +1344,13 @@ handle_link_controllers (void *cls,
1352 struct LCFContextQueue *lcfq; 1344 struct LCFContextQueue *lcfq;
1353 struct Route *route; 1345 struct Route *route;
1354 struct Route *new_route; 1346 struct Route *new_route;
1355 char *config; 1347 char *config;
1356 uLongf dest_size; 1348 uLongf dest_size;
1357 size_t config_size; 1349 size_t config_size;
1358 uint32_t delegated_host_id; 1350 uint32_t delegated_host_id;
1359 uint32_t slave_host_id; 1351 uint32_t slave_host_id;
1360 uint16_t msize; 1352 uint16_t msize;
1361 1353
1362 if (NULL == master_context) 1354 if (NULL == master_context)
1363 { 1355 {
1364 GNUNET_break (0); 1356 GNUNET_break (0);
@@ -1381,7 +1373,7 @@ handle_link_controllers (void *cls,
1381 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1373 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1382 return; 1374 return;
1383 } 1375 }
1384 if ((delegated_host_id >= host_list_size) || 1376 if ((delegated_host_id >= host_list_size) ||
1385 (NULL == host_list[delegated_host_id])) 1377 (NULL == host_list[delegated_host_id]))
1386 { 1378 {
1387 LOG (GNUNET_ERROR_TYPE_WARNING, "Delegated host not registered with us\n"); 1379 LOG (GNUNET_ERROR_TYPE_WARNING, "Delegated host not registered with us\n");
@@ -1400,28 +1392,28 @@ handle_link_controllers (void *cls,
1400 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n"); 1392 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1401 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1393 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1402 return; 1394 return;
1403 } 1395 }
1404 1396
1405 if (slave_host_id == master_context->host_id) /* Link from us */ 1397 if (slave_host_id == master_context->host_id) /* Link from us */
1406 { 1398 {
1407 struct Slave *slave; 1399 struct Slave *slave;
1408 1400
1409 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage); 1401 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1410 config_size = ntohs (msg->config_size); 1402 config_size = ntohs (msg->config_size);
1411 if ((delegated_host_id < slave_list_size) && 1403 if ((delegated_host_id < slave_list_size) && (NULL != slave_list[delegated_host_id])) /* We have already added */
1412 (NULL != slave_list[delegated_host_id])) /* We have already added */
1413 { 1404 {
1414 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n", 1405 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1415 delegated_host_id); 1406 delegated_host_id);
1416 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1407 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1417 return; 1408 return;
1418 } 1409 }
1419 config = GNUNET_malloc (config_size); 1410 config = GNUNET_malloc (config_size);
1420 dest_size = (uLongf) config_size; 1411 dest_size = (uLongf) config_size;
1421 if (Z_OK != uncompress ((Bytef *) config, &dest_size, 1412 if (Z_OK !=
1422 (const Bytef *) &msg[1], (uLong) msize)) 1413 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1414 (uLong) msize))
1423 { 1415 {
1424 GNUNET_break (0); /* Compression error */ 1416 GNUNET_break (0); /* Compression error */
1425 GNUNET_free (config); 1417 GNUNET_free (config);
1426 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1418 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1427 return; 1419 return;
@@ -1433,50 +1425,51 @@ handle_link_controllers (void *cls,
1433 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1425 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1434 return; 1426 return;
1435 } 1427 }
1436 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */ 1428 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1437 if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, 1429 if (GNUNET_OK !=
1438 GNUNET_NO)) 1430 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1439 { 1431 {
1440 GNUNET_break (0); /* Configuration parsing error */ 1432 GNUNET_break (0); /* Configuration parsing error */
1441 GNUNET_free (config); 1433 GNUNET_free (config);
1442 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1434 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1443 return; 1435 return;
1444 } 1436 }
1445 GNUNET_free (config); 1437 GNUNET_free (config);
1446 if ((delegated_host_id < slave_list_size) && 1438 if ((delegated_host_id < slave_list_size) &&
1447 (NULL != slave_list[delegated_host_id])) 1439 (NULL != slave_list[delegated_host_id]))
1448 { 1440 {
1449 GNUNET_break (0); /* Configuration parsing error */ 1441 GNUNET_break (0); /* Configuration parsing error */
1450 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1442 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1451 return; 1443 return;
1452 } 1444 }
1453 slave = GNUNET_malloc (sizeof (struct Slave)); 1445 slave = GNUNET_malloc (sizeof (struct Slave));
1454 slave->host_id = delegated_host_id; 1446 slave->host_id = delegated_host_id;
1455 slave_list_add (slave); 1447 slave_list_add (slave);
1456 if (1 == msg->is_subordinate) 1448 if (1 == msg->is_subordinate)
1457 { 1449 {
1458 struct LinkControllersContext *lcc; 1450 struct LinkControllersContext *lcc;
1451
1459 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext)); 1452 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1460 lcc->operation_id = GNUNET_ntohll (msg->operation_id); 1453 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1461 GNUNET_SERVER_client_keep (client); 1454 GNUNET_SERVER_client_keep (client);
1462 lcc->client = client; 1455 lcc->client = client;
1463 lcc->slave = slave; 1456 lcc->slave = slave;
1464 slave->controller_proc = 1457 slave->controller_proc =
1465 GNUNET_TESTBED_controller_start (master_context->master_ip, 1458 GNUNET_TESTBED_controller_start (master_context->master_ip,
1466 host_list[slave->host_id], 1459 host_list[slave->host_id], cfg,
1467 cfg, &slave_status_callback, 1460 &slave_status_callback, lcc);
1468 lcc);
1469 } 1461 }
1470 else { 1462 else
1471 slave->controller = 1463 {
1472 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id], 1464 slave->controller =
1473 master_context->event_mask, 1465 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1474 &slave_event_callback, slave); 1466 master_context->event_mask,
1467 &slave_event_callback, slave);
1475 if (NULL != slave->controller) 1468 if (NULL != slave->controller)
1476 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id)); 1469 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1477 else 1470 else
1478 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), 1471 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1479 "Could not connect to delegated controller"); 1472 "Could not connect to delegated controller");
1480 } 1473 }
1481 GNUNET_CONFIGURATION_destroy (cfg); 1474 GNUNET_CONFIGURATION_destroy (cfg);
1482 new_route = GNUNET_malloc (sizeof (struct Route)); 1475 new_route = GNUNET_malloc (sizeof (struct Route));
@@ -1499,9 +1492,9 @@ handle_link_controllers (void *cls,
1499 lcfq->lcf->delegated_host_id = delegated_host_id; 1492 lcfq->lcf->delegated_host_id = delegated_host_id;
1500 lcfq->lcf->slave_host_id = slave_host_id; 1493 lcfq->lcf->slave_host_id = slave_host_id;
1501 route = find_dest_route (slave_host_id); 1494 route = find_dest_route (slave_host_id);
1502 GNUNET_assert (NULL != route); /* because we add routes carefully */ 1495 GNUNET_assert (NULL != route); /* because we add routes carefully */
1503 GNUNET_assert (route->dest < slave_list_size); 1496 GNUNET_assert (route->dest < slave_list_size);
1504 GNUNET_assert (NULL != slave_list[route->dest]); 1497 GNUNET_assert (NULL != slave_list[route->dest]);
1505 lcfq->lcf->state = INIT; 1498 lcfq->lcf->state = INIT;
1506 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id); 1499 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1507 lcfq->lcf->gateway = slave_list[route->dest]; 1500 lcfq->lcf->gateway = slave_list[route->dest];
@@ -1518,7 +1511,7 @@ handle_link_controllers (void *cls,
1518 else 1511 else
1519 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq); 1512 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1520 /* FIXME: Adding a new route should happen after the controllers are linked 1513 /* FIXME: Adding a new route should happen after the controllers are linked
1521 successfully */ 1514 * successfully */
1522 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1515 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1523 new_route = GNUNET_malloc (sizeof (struct Route)); 1516 new_route = GNUNET_malloc (sizeof (struct Route));
1524 new_route->dest = delegated_host_id; 1517 new_route->dest = delegated_host_id;
@@ -1539,13 +1532,12 @@ peer_create_forward_timeout (void *cls,
1539 const struct GNUNET_SCHEDULER_TaskContext *tc) 1532 const struct GNUNET_SCHEDULER_TaskContext *tc)
1540{ 1533{
1541 struct ForwardedOperationContext *fo_ctxt = cls; 1534 struct ForwardedOperationContext *fo_ctxt = cls;
1542 1535
1543 /* send error msg to client */ 1536 /* send error msg to client */
1544 send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, 1537 send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, "Timedout");
1545 "Timedout");
1546 GNUNET_SERVER_client_drop (fo_ctxt->client); 1538 GNUNET_SERVER_client_drop (fo_ctxt->client);
1547 GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc); 1539 GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc);
1548 GNUNET_free (fo_ctxt); 1540 GNUNET_free (fo_ctxt);
1549} 1541}
1550 1542
1551 1543
@@ -1557,33 +1549,32 @@ peer_create_forward_timeout (void *cls,
1557 * @param msg the peer create success message 1549 * @param msg the peer create success message
1558 */ 1550 */
1559static void 1551static void
1560peer_create_success_cb (void *cls, 1552peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1561 const struct GNUNET_MessageHeader *msg)
1562{ 1553{
1563 struct ForwardedOperationContext *fo_ctxt = cls; 1554 struct ForwardedOperationContext *fo_ctxt = cls;
1564 const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *success_msg; 1555 const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *success_msg;
1565 struct GNUNET_MessageHeader *dup_msg; 1556 struct GNUNET_MessageHeader *dup_msg;
1566 struct Peer *peer; 1557 struct Peer *peer;
1567 uint16_t msize; 1558 uint16_t msize;
1568 1559
1569 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task); 1560 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);
1570 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS) 1561 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
1571 { 1562 {
1572 success_msg 1563 success_msg =
1573 = (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *) msg; 1564 (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *) msg;
1574 peer = GNUNET_malloc (sizeof (struct Peer)); 1565 peer = GNUNET_malloc (sizeof (struct Peer));
1575 peer->is_remote = GNUNET_YES; 1566 peer->is_remote = GNUNET_YES;
1576 peer->id = ntohl (success_msg->peer_id); 1567 peer->id = ntohl (success_msg->peer_id);
1577 GNUNET_assert (NULL != fo_ctxt->cls); 1568 GNUNET_assert (NULL != fo_ctxt->cls);
1578 peer->details.remote.controller = fo_ctxt->cls; 1569 peer->details.remote.controller = fo_ctxt->cls;
1579 peer_list_add (peer); 1570 peer_list_add (peer);
1580 } 1571 }
1581 msize = ntohs (msg->size); 1572 msize = ntohs (msg->size);
1582 dup_msg = GNUNET_malloc (msize); 1573 dup_msg = GNUNET_malloc (msize);
1583 (void) memcpy (dup_msg, msg, msize); 1574 (void) memcpy (dup_msg, msg, msize);
1584 queue_message (fo_ctxt->client, dup_msg); 1575 queue_message (fo_ctxt->client, dup_msg);
1585 GNUNET_SERVER_client_drop (fo_ctxt->client); 1576 GNUNET_SERVER_client_drop (fo_ctxt->client);
1586 GNUNET_free (fo_ctxt); 1577 GNUNET_free (fo_ctxt);
1587} 1578}
1588 1579
1589 1580
@@ -1595,9 +1586,8 @@ peer_create_success_cb (void *cls,
1595 * @param client identification of the client 1586 * @param client identification of the client
1596 * @param message the actual message 1587 * @param message the actual message
1597 */ 1588 */
1598static void 1589static void
1599handle_peer_create (void *cls, 1590handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1600 struct GNUNET_SERVER_Client *client,
1601 const struct GNUNET_MessageHeader *message) 1591 const struct GNUNET_MessageHeader *message)
1602{ 1592{
1603 const struct GNUNET_TESTBED_PeerCreateMessage *msg; 1593 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
@@ -1613,7 +1603,7 @@ handle_peer_create (void *cls,
1613 uint32_t host_id; 1603 uint32_t host_id;
1614 uint32_t peer_id; 1604 uint32_t peer_id;
1615 uint16_t msize; 1605 uint16_t msize;
1616 1606
1617 1607
1618 msize = ntohs (message->size); 1608 msize = ntohs (message->size);
1619 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage)) 1609 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
@@ -1635,31 +1625,33 @@ handle_peer_create (void *cls,
1635 if (host_id == master_context->host_id) 1625 if (host_id == master_context->host_id)
1636 { 1626 {
1637 char *emsg; 1627 char *emsg;
1638 1628
1639 /* We are responsible for this peer */ 1629 /* We are responsible for this peer */
1640 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage); 1630 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1641 config_size = ntohl (msg->config_size); 1631 config_size = ntohl (msg->config_size);
1642 config = GNUNET_malloc (config_size); 1632 config = GNUNET_malloc (config_size);
1643 dest_size = config_size; 1633 dest_size = config_size;
1644 if (Z_OK != (ret = uncompress ((Bytef *) config, (uLongf *) &dest_size, 1634 if (Z_OK !=
1645 (const Bytef *) &msg[1], (uLong) msize))) 1635 (ret =
1636 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1637 (const Bytef *) &msg[1], (uLong) msize)))
1646 { 1638 {
1647 GNUNET_break (0); /* uncompression error */ 1639 GNUNET_break (0); /* uncompression error */
1648 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1640 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1649 return; 1641 return;
1650 } 1642 }
1651 if (config_size != dest_size) 1643 if (config_size != dest_size)
1652 { 1644 {
1653 GNUNET_break (0);/* Uncompressed config size mismatch */ 1645 GNUNET_break (0); /* Uncompressed config size mismatch */
1654 GNUNET_free (config); 1646 GNUNET_free (config);
1655 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1647 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1656 return; 1648 return;
1657 } 1649 }
1658 cfg = GNUNET_CONFIGURATION_create (); 1650 cfg = GNUNET_CONFIGURATION_create ();
1659 if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, 1651 if (GNUNET_OK !=
1660 GNUNET_NO)) 1652 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1661 { 1653 {
1662 GNUNET_break (0); /* Configuration parsing error */ 1654 GNUNET_break (0); /* Configuration parsing error */
1663 GNUNET_free (config); 1655 GNUNET_free (config);
1664 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1656 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1665 return; 1657 return;
@@ -1670,11 +1662,11 @@ handle_peer_create (void *cls,
1670 peer->details.local.cfg = cfg; 1662 peer->details.local.cfg = cfg;
1671 peer->id = peer_id; 1663 peer->id = peer_id;
1672 LOG_DEBUG ("Creating peer with id: %u\n", peer->id); 1664 LOG_DEBUG ("Creating peer with id: %u\n", peer->id);
1673 peer->details.local.peer = 1665 peer->details.local.peer =
1674 GNUNET_TESTING_peer_configure (master_context->system, 1666 GNUNET_TESTING_peer_configure (master_context->system,
1675 peer->details.local.cfg, peer->id, 1667 peer->details.local.cfg, peer->id,
1676 NULL /* Peer id */, 1668 NULL /* Peer id */ ,
1677 &emsg); 1669 &emsg);
1678 if (NULL == peer->details.local.peer) 1670 if (NULL == peer->details.local.peer)
1679 { 1671 {
1680 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg); 1672 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
@@ -1685,8 +1677,11 @@ handle_peer_create (void *cls,
1685 return; 1677 return;
1686 } 1678 }
1687 peer_list_add (peer); 1679 peer_list_add (peer);
1688 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)); 1680 reply =
1689 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)); 1681 GNUNET_malloc (sizeof
1682 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1683 reply->header.size =
1684 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1690 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS); 1685 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
1691 reply->peer_id = msg->peer_id; 1686 reply->peer_id = msg->peer_id;
1692 reply->operation_id = msg->operation_id; 1687 reply->operation_id = msg->operation_id;
@@ -1694,7 +1689,7 @@ handle_peer_create (void *cls,
1694 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1689 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1695 return; 1690 return;
1696 } 1691 }
1697 1692
1698 /* Forward peer create request */ 1693 /* Forward peer create request */
1699 route = find_dest_route (host_id); 1694 route = find_dest_route (host_id);
1700 if (NULL == route) 1695 if (NULL == route)
@@ -1706,17 +1701,18 @@ handle_peer_create (void *cls,
1706 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); 1701 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1707 GNUNET_SERVER_client_keep (client); 1702 GNUNET_SERVER_client_keep (client);
1708 fo_ctxt->client = client; 1703 fo_ctxt->client = client;
1709 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); 1704 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1710 fo_ctxt->cls = slave_list[route->dest]->controller; 1705 fo_ctxt->cls = slave_list[route->dest]->controller;
1711 fo_ctxt->opc = 1706 fo_ctxt->opc =
1712 GNUNET_TESTBED_forward_operation_msg_ (slave_list[route->dest]->controller, 1707 GNUNET_TESTBED_forward_operation_msg_ (slave_list
1713 fo_ctxt->operation_id, 1708 [route->dest]->controller,
1714 &msg->header, 1709 fo_ctxt->operation_id,
1715 peer_create_success_cb, fo_ctxt); 1710 &msg->header,
1716 fo_ctxt->timeout_task = 1711 peer_create_success_cb, fo_ctxt);
1717 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 1712 fo_ctxt->timeout_task =
1718 &peer_create_forward_timeout, fo_ctxt); 1713 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
1719 1714 fo_ctxt);
1715
1720 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1716 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1721} 1717}
1722 1718
@@ -1728,20 +1724,19 @@ handle_peer_create (void *cls,
1728 * @param client identification of the client 1724 * @param client identification of the client
1729 * @param message the actual message 1725 * @param message the actual message
1730 */ 1726 */
1731static void 1727static void
1732handle_peer_destroy (void *cls, 1728handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
1733 struct GNUNET_SERVER_Client *client,
1734 const struct GNUNET_MessageHeader *message) 1729 const struct GNUNET_MessageHeader *message)
1735{ 1730{
1736 const struct GNUNET_TESTBED_PeerDestroyMessage *msg; 1731 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1737 struct ForwardedOperationContext *fopc; 1732 struct ForwardedOperationContext *fopc;
1738 struct Peer *peer; 1733 struct Peer *peer;
1739 uint32_t peer_id; 1734 uint32_t peer_id;
1740 1735
1741 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message; 1736 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1742 peer_id = ntohl (msg->peer_id); 1737 peer_id = ntohl (msg->peer_id);
1743 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n", 1738 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1744 peer_id, GNUNET_ntohll (msg->operation_id)); 1739 peer_id, GNUNET_ntohll (msg->operation_id));
1745 if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id])) 1740 if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id]))
1746 { 1741 {
1747 LOG (GNUNET_ERROR_TYPE_ERROR, 1742 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -1756,18 +1751,17 @@ handle_peer_destroy (void *cls,
1756 { 1751 {
1757 /* Forward the destory message to sub controller */ 1752 /* Forward the destory message to sub controller */
1758 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); 1753 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1759 GNUNET_SERVER_client_keep (client); 1754 GNUNET_SERVER_client_keep (client);
1760 fopc->client = client; 1755 fopc->client = client;
1761 fopc->operation_id = GNUNET_ntohll (msg->operation_id); 1756 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1762 fopc->opc = 1757 fopc->opc =
1763 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller, 1758 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
1764 fopc->operation_id, 1759 fopc->operation_id, &msg->header,
1765 &msg->header, 1760 &forwarded_operation_reply_relay,
1766 &forwarded_operation_reply_relay, 1761 fopc);
1767 fopc);
1768 fopc->timeout_task = 1762 fopc->timeout_task =
1769 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 1763 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1770 &forwarded_operation_timeout, fopc); 1764 fopc);
1771 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1765 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1772 return; 1766 return;
1773 } 1767 }
@@ -1787,10 +1781,9 @@ handle_peer_destroy (void *cls,
1787 * @param client identification of the client 1781 * @param client identification of the client
1788 * @param message the actual message 1782 * @param message the actual message
1789 */ 1783 */
1790static void 1784static void
1791handle_peer_start (void *cls, 1785handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
1792 struct GNUNET_SERVER_Client *client, 1786 const struct GNUNET_MessageHeader *message)
1793 const struct GNUNET_MessageHeader *message)
1794{ 1787{
1795 const struct GNUNET_TESTBED_PeerStartMessage *msg; 1788 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1796 struct GNUNET_TESTBED_PeerEventMessage *reply; 1789 struct GNUNET_TESTBED_PeerEventMessage *reply;
@@ -1800,12 +1793,11 @@ handle_peer_start (void *cls,
1800 1793
1801 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message; 1794 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
1802 peer_id = ntohl (msg->peer_id); 1795 peer_id = ntohl (msg->peer_id);
1803 if ((peer_id >= peer_list_size) 1796 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
1804 || (NULL == peer_list[peer_id]))
1805 { 1797 {
1806 GNUNET_break (0); 1798 GNUNET_break (0);
1807 LOG (GNUNET_ERROR_TYPE_ERROR, 1799 LOG (GNUNET_ERROR_TYPE_ERROR,
1808 "Asked to start a non existent peer with id: %u\n", peer_id); 1800 "Asked to start a non existent peer with id: %u\n", peer_id);
1809 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1801 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1810 return; 1802 return;
1811 } 1803 }
@@ -1813,23 +1805,21 @@ handle_peer_start (void *cls,
1813 if (GNUNET_YES == peer->is_remote) 1805 if (GNUNET_YES == peer->is_remote)
1814 { 1806 {
1815 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); 1807 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1816 GNUNET_SERVER_client_keep (client); 1808 GNUNET_SERVER_client_keep (client);
1817 fopc->client = client; 1809 fopc->client = client;
1818 fopc->operation_id = GNUNET_ntohll (msg->operation_id); 1810 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1819 fopc->opc = 1811 fopc->opc =
1820 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller, 1812 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
1821 fopc->operation_id, 1813 fopc->operation_id, &msg->header,
1822 &msg->header, 1814 &forwarded_operation_reply_relay,
1823 &forwarded_operation_reply_relay, 1815 fopc);
1824 fopc);
1825 fopc->timeout_task = 1816 fopc->timeout_task =
1826 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 1817 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1827 &forwarded_operation_timeout, fopc); 1818 fopc);
1828 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1819 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1829 return; 1820 return;
1830 } 1821 }
1831 if (GNUNET_OK != 1822 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
1832 GNUNET_TESTING_peer_start (peer->details.local.peer))
1833 { 1823 {
1834 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), 1824 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1835 "Failed to start"); 1825 "Failed to start");
@@ -1855,10 +1845,9 @@ handle_peer_start (void *cls,
1855 * @param client identification of the client 1845 * @param client identification of the client
1856 * @param message the actual message 1846 * @param message the actual message
1857 */ 1847 */
1858static void 1848static void
1859handle_peer_stop (void *cls, 1849handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
1860 struct GNUNET_SERVER_Client *client, 1850 const struct GNUNET_MessageHeader *message)
1861 const struct GNUNET_MessageHeader *message)
1862{ 1851{
1863 const struct GNUNET_TESTBED_PeerStopMessage *msg; 1852 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1864 struct GNUNET_TESTBED_PeerEventMessage *reply; 1853 struct GNUNET_TESTBED_PeerEventMessage *reply;
@@ -1869,7 +1858,7 @@ handle_peer_stop (void *cls,
1869 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message; 1858 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
1870 peer_id = ntohl (msg->peer_id); 1859 peer_id = ntohl (msg->peer_id);
1871 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id])) 1860 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
1872 { 1861 {
1873 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), 1862 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1874 "Peer not found"); 1863 "Peer not found");
1875 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1864 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1879,23 +1868,21 @@ handle_peer_stop (void *cls,
1879 if (GNUNET_YES == peer->is_remote) 1868 if (GNUNET_YES == peer->is_remote)
1880 { 1869 {
1881 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); 1870 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1882 GNUNET_SERVER_client_keep (client); 1871 GNUNET_SERVER_client_keep (client);
1883 fopc->client = client; 1872 fopc->client = client;
1884 fopc->operation_id = GNUNET_ntohll (msg->operation_id); 1873 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1885 fopc->opc = 1874 fopc->opc =
1886 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller, 1875 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
1887 fopc->operation_id, 1876 fopc->operation_id, &msg->header,
1888 &msg->header, 1877 &forwarded_operation_reply_relay,
1889 &forwarded_operation_reply_relay, 1878 fopc);
1890 fopc);
1891 fopc->timeout_task = 1879 fopc->timeout_task =
1892 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 1880 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1893 &forwarded_operation_timeout, fopc); 1881 fopc);
1894 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1882 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1895 return; 1883 return;
1896 } 1884 }
1897 if (GNUNET_OK != 1885 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer->details.local.peer))
1898 GNUNET_TESTING_peer_stop (peer->details.local.peer))
1899 { 1886 {
1900 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), 1887 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1901 "Peer not running"); 1888 "Peer not running");
@@ -1921,9 +1908,8 @@ handle_peer_stop (void *cls,
1921 * @param client identification of the client 1908 * @param client identification of the client
1922 * @param message the actual message 1909 * @param message the actual message
1923 */ 1910 */
1924static void 1911static void
1925handle_peer_get_config (void *cls, 1912handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1926 struct GNUNET_SERVER_Client *client,
1927 const struct GNUNET_MessageHeader *message) 1913 const struct GNUNET_MessageHeader *message)
1928{ 1914{
1929 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; 1915 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
@@ -1932,10 +1918,10 @@ handle_peer_get_config (void *cls,
1932 char *config; 1918 char *config;
1933 char *xconfig; 1919 char *xconfig;
1934 size_t c_size; 1920 size_t c_size;
1935 size_t xc_size; 1921 size_t xc_size;
1936 uint32_t peer_id; 1922 uint32_t peer_id;
1937 uint16_t msize; 1923 uint16_t msize;
1938 1924
1939 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message; 1925 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
1940 peer_id = ntohl (msg->peer_id); 1926 peer_id = ntohl (msg->peer_id);
1941 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id])) 1927 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
@@ -1954,12 +1940,13 @@ handle_peer_get_config (void *cls,
1954 return; 1940 return;
1955 } 1941 }
1956 config = 1942 config =
1957 GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->details.local.cfg, 1943 GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->details.local.cfg,
1958 &c_size); 1944 &c_size);
1959 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); 1945 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
1960 GNUNET_free (config); 1946 GNUNET_free (config);
1961 msize = xc_size + sizeof (struct 1947 msize =
1962 GNUNET_TESTBED_PeerConfigurationInformationMessage); 1948 xc_size +
1949 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1963 reply = GNUNET_realloc (xconfig, msize); 1950 reply = GNUNET_realloc (xconfig, msize);
1964 (void) memmove (&reply[1], reply, xc_size); 1951 (void) memmove (&reply[1], reply, xc_size);
1965 reply->header.size = htons (msize); 1952 reply->header.size = htons (msize);
@@ -2030,11 +2017,10 @@ timeout_overlay_connect (void *cls,
2030 * @param ats performance data 2017 * @param ats performance data
2031 * @param ats_count number of entries in ats (excluding 0-termination) 2018 * @param ats_count number of entries in ats (excluding 0-termination)
2032 */ 2019 */
2033static void 2020static void
2034overlay_connect_notify (void *cls, 2021overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2035 const struct GNUNET_PeerIdentity * new_peer, 2022 const struct GNUNET_ATS_Information *ats,
2036 const struct GNUNET_ATS_Information * ats, 2023 unsigned int ats_count)
2037 unsigned int ats_count)
2038{ 2024{
2039 struct OverlayConnectContext *occ = cls; 2025 struct OverlayConnectContext *occ = cls;
2040 struct GNUNET_TESTBED_ConnectionEventMessage *msg; 2026 struct GNUNET_TESTBED_ConnectionEventMessage *msg;
@@ -2042,16 +2028,18 @@ overlay_connect_notify (void *cls,
2042 char *other_peer_str; 2028 char *other_peer_str;
2043 2029
2044 LOG_DEBUG ("Overlay connect notify\n"); 2030 LOG_DEBUG ("Overlay connect notify\n");
2045 if (0 == memcmp (new_peer, &occ->peer_identity, 2031 if (0 ==
2046 sizeof (struct GNUNET_PeerIdentity))) 2032 memcmp (new_peer, &occ->peer_identity,
2033 sizeof (struct GNUNET_PeerIdentity)))
2047 return; 2034 return;
2048 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer)); 2035 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer));
2049 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); 2036 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2050 if (0 != memcmp (new_peer, &occ->other_peer_identity, 2037 if (0 !=
2051 sizeof (struct GNUNET_PeerIdentity))) 2038 memcmp (new_peer, &occ->other_peer_identity,
2039 sizeof (struct GNUNET_PeerIdentity)))
2052 { 2040 {
2053 LOG_DEBUG ("Unexpected peer %4s connected to peer %4s\n", 2041 LOG_DEBUG ("Unexpected peer %4s connected to peer %4s\n", new_peer_str,
2054 new_peer_str, other_peer_str); 2042 other_peer_str);
2055 GNUNET_free (new_peer_str); 2043 GNUNET_free (new_peer_str);
2056 GNUNET_free (other_peer_str); 2044 GNUNET_free (other_peer_str);
2057 return; 2045 return;
@@ -2074,8 +2062,8 @@ overlay_connect_notify (void *cls,
2074 /* Peer 1 has connected connect to peer2 - now send overlay connect success message */ 2062 /* Peer 1 has connected connect to peer2 - now send overlay connect success message */
2075 LOG_DEBUG ("Peers connected - Sending overlay connect success\n"); 2063 LOG_DEBUG ("Peers connected - Sending overlay connect success\n");
2076 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage)); 2064 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2077 msg->header.size = htons (sizeof (struct 2065 msg->header.size =
2078 GNUNET_TESTBED_ConnectionEventMessage)); 2066 htons (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2079 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT); 2067 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT);
2080 msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT); 2068 msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
2081 msg->peer1 = htonl (occ->peer->id); 2069 msg->peer1 = htonl (occ->peer->id);
@@ -2098,12 +2086,13 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2098 return; 2086 return;
2099 GNUNET_assert (NULL != occ->hello); 2087 GNUNET_assert (NULL != occ->hello);
2100 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); 2088 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2101 LOG_DEBUG ("Offering HELLO of %s to %s\n", other_peer_str, GNUNET_i2s (&occ->peer_identity)); 2089 LOG_DEBUG ("Offering HELLO of %s to %s\n", other_peer_str,
2090 GNUNET_i2s (&occ->peer_identity));
2102 GNUNET_free (other_peer_str); 2091 GNUNET_free (other_peer_str);
2103 GNUNET_TRANSPORT_offer_hello (occ->p1th, occ->hello, NULL, NULL); 2092 GNUNET_TRANSPORT_offer_hello (occ->p1th, occ->hello, NULL, NULL);
2104 GNUNET_TRANSPORT_try_connect (occ->p1th, &occ->other_peer_identity); 2093 GNUNET_TRANSPORT_try_connect (occ->p1th, &occ->other_peer_identity);
2105 occ->send_hello_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 2094 occ->send_hello_task =
2106 &send_hello, occ); 2095 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &send_hello, occ);
2107} 2096}
2108 2097
2109/** 2098/**
@@ -2112,7 +2101,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2112 * @param cls empty flag to set 2101 * @param cls empty flag to set
2113 * @param address the HELLO 2102 * @param address the HELLO
2114 * @param expiration expiration of the HELLO 2103 * @param expiration expiration of the HELLO
2115 * @return 2104 * @return
2116 */ 2105 */
2117static int 2106static int
2118test_address (void *cls, const struct GNUNET_HELLO_Address *address, 2107test_address (void *cls, const struct GNUNET_HELLO_Address *address,
@@ -2132,28 +2121,29 @@ test_address (void *cls, const struct GNUNET_HELLO_Address *address,
2132 * @param cls closure 2121 * @param cls closure
2133 * @param hello our updated HELLO 2122 * @param hello our updated HELLO
2134 */ 2123 */
2135static void 2124static void
2136hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello) 2125hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2137{ 2126{
2138 struct OverlayConnectContext *occ = cls; 2127 struct OverlayConnectContext *occ = cls;
2139 int empty; 2128 int empty;
2140 uint16_t msize; 2129 uint16_t msize;
2141 2130
2142 msize = ntohs (hello->size); 2131 msize = ntohs (hello->size);
2143 if (msize < 0) 2132 if (msize < 0)
2144 { 2133 {
2145 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2134 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2146 "HELLO message of peer %s is of size 0\n", 2135 "HELLO message of peer %s is of size 0\n",
2147 &occ->other_peer_identity); 2136 &occ->other_peer_identity);
2148 return; 2137 return;
2149 } 2138 }
2150 empty = GNUNET_YES; 2139 empty = GNUNET_YES;
2151 (void) 2140 (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *)
2152 GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *) hello, 2141 hello, GNUNET_NO, &test_address,
2153 GNUNET_NO, &test_address, &empty); 2142 &empty);
2154 if (GNUNET_YES == empty) 2143 if (GNUNET_YES == empty)
2155 { 2144 {
2156 LOG_DEBUG ("HELLO of %s is empty\n", GNUNET_i2s (&occ->other_peer_identity)); 2145 LOG_DEBUG ("HELLO of %s is empty\n",
2146 GNUNET_i2s (&occ->other_peer_identity));
2157 return; 2147 return;
2158 } 2148 }
2159 LOG_DEBUG ("Received HELLO of %s\n", GNUNET_i2s (&occ->other_peer_identity)); 2149 LOG_DEBUG ("Received HELLO of %s\n", GNUNET_i2s (&occ->other_peer_identity));
@@ -2163,7 +2153,7 @@ hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2163 occ->ghh = NULL; 2153 occ->ghh = NULL;
2164 GNUNET_TRANSPORT_disconnect (occ->p2th); 2154 GNUNET_TRANSPORT_disconnect (occ->p2th);
2165 occ->p2th = NULL; 2155 occ->p2th = NULL;
2166 GNUNET_free_non_null (occ->emsg); 2156 GNUNET_free_non_null (occ->emsg);
2167 occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer"); 2157 occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer");
2168 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); 2158 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
2169} 2159}
@@ -2180,39 +2170,40 @@ hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2180 * @param server handle to the server, NULL if we failed 2170 * @param server handle to the server, NULL if we failed
2181 * @param my_identity ID of this peer, NULL if we failed 2171 * @param my_identity ID of this peer, NULL if we failed
2182 */ 2172 */
2183static void 2173static void
2184core_startup_cb (void *cls, struct GNUNET_CORE_Handle * server, 2174core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
2185 const struct GNUNET_PeerIdentity *my_identity) 2175 const struct GNUNET_PeerIdentity *my_identity)
2186{ 2176{
2187 struct OverlayConnectContext *occ = cls; 2177 struct OverlayConnectContext *occ = cls;
2188 2178
2189 GNUNET_free_non_null (occ->emsg); 2179 GNUNET_free_non_null (occ->emsg);
2190 occ->emsg = NULL; 2180 occ->emsg = NULL;
2191 memcpy (&occ->peer_identity, my_identity, sizeof (struct GNUNET_PeerIdentity)); 2181 memcpy (&occ->peer_identity, my_identity,
2182 sizeof (struct GNUNET_PeerIdentity));
2192 occ->p1th = 2183 occ->p1th =
2193 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg, 2184 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg,
2194 &occ->peer_identity, NULL, NULL, NULL, NULL); 2185 &occ->peer_identity, NULL, NULL, NULL, NULL);
2195 /* Connect to the transport of 2nd peer and get its HELLO message */ 2186 /* Connect to the transport of 2nd peer and get its HELLO message */
2196 GNUNET_TESTING_peer_get_identity (occ->other_peer->details.local.peer, 2187 GNUNET_TESTING_peer_get_identity (occ->other_peer->details.local.peer,
2197 &occ->other_peer_identity); 2188 &occ->other_peer_identity);
2198 occ->p2th = 2189 occ->p2th =
2199 GNUNET_TRANSPORT_connect (occ->other_peer->details.local.cfg, 2190 GNUNET_TRANSPORT_connect (occ->other_peer->details.local.cfg,
2200 &occ->other_peer_identity, 2191 &occ->other_peer_identity, NULL, NULL, NULL,
2201 NULL, NULL, NULL, NULL); 2192 NULL);
2202 if ((NULL == occ->p1th) || (NULL == occ->p2th)) 2193 if ((NULL == occ->p1th) || (NULL == occ->p2th))
2203 { 2194 {
2204 occ->emsg = GNUNET_strdup ("Cannot connect to TRANSPORTs of peers"); 2195 occ->emsg = GNUNET_strdup ("Cannot connect to TRANSPORTs of peers");
2205 goto send_failure; 2196 goto send_failure;
2206 } 2197 }
2207 LOG_DEBUG ("Acquiring HELLO of peer %s\n", GNUNET_i2s 2198 LOG_DEBUG ("Acquiring HELLO of peer %s\n",
2208 (&occ->other_peer_identity)); 2199 GNUNET_i2s (&occ->other_peer_identity));
2209 occ->emsg = GNUNET_strdup ("Timeout while acquiring HELLO message"); 2200 occ->emsg = GNUNET_strdup ("Timeout while acquiring HELLO message");
2210 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p2th, &hello_update_cb, occ); 2201 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p2th, &hello_update_cb, occ);
2211 return; 2202 return;
2212 2203
2213 send_failure: 2204send_failure:
2214 GNUNET_SCHEDULER_cancel (occ->timeout_task); 2205 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2215 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); 2206 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2216} 2207}
2217 2208
2218 2209
@@ -2223,13 +2214,13 @@ core_startup_cb (void *cls, struct GNUNET_CORE_Handle * server,
2223 * @param client identification of the client 2214 * @param client identification of the client
2224 * @param message the actual message 2215 * @param message the actual message
2225 */ 2216 */
2226static void 2217static void
2227handle_overlay_connect (void *cls, 2218handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
2228 struct GNUNET_SERVER_Client *client,
2229 const struct GNUNET_MessageHeader *message) 2219 const struct GNUNET_MessageHeader *message)
2230{ 2220{
2231 const struct GNUNET_TESTBED_OverlayConnectMessage *msg; 2221 const struct GNUNET_TESTBED_OverlayConnectMessage *msg;
2232 struct OverlayConnectContext *occ; 2222 struct OverlayConnectContext *occ;
2223
2233 struct GNUNET_CORE_MessageHandler no_handlers[] = { 2224 struct GNUNET_CORE_MessageHandler no_handlers[] = {
2234 {NULL, 0, 0} 2225 {NULL, 0, 0}
2235 }; 2226 };
@@ -2244,7 +2235,7 @@ handle_overlay_connect (void *cls,
2244 GNUNET_assert (p2 < peer_list_size); 2235 GNUNET_assert (p2 < peer_list_size);
2245 GNUNET_assert (NULL != peer_list[p2]); 2236 GNUNET_assert (NULL != peer_list[p2]);
2246 /* FIXME: Add cases where we have to forward overlay connect message to sub 2237 /* FIXME: Add cases where we have to forward overlay connect message to sub
2247 controllers */ 2238 * controllers */
2248 occ = GNUNET_malloc (sizeof (struct OverlayConnectContext)); 2239 occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
2249 GNUNET_SERVER_client_keep (client); 2240 GNUNET_SERVER_client_keep (client);
2250 occ->client = client; 2241 occ->client = client;
@@ -2253,15 +2244,15 @@ handle_overlay_connect (void *cls,
2253 occ->other_peer = peer_list[p2]; 2244 occ->other_peer = peer_list[p2];
2254 occ->op_id = GNUNET_ntohll (msg->operation_id); 2245 occ->op_id = GNUNET_ntohll (msg->operation_id);
2255 occ->timeout_task = 2246 occ->timeout_task =
2256 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 2247 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2257 (GNUNET_TIME_UNIT_SECONDS, 30), 2248 (GNUNET_TIME_UNIT_SECONDS, 30),
2258 &timeout_overlay_connect, occ); 2249 &timeout_overlay_connect, occ);
2259 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ 2250 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */
2260 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE"); 2251 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2261 occ->ch = 2252 occ->ch =
2262 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb, 2253 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2263 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, 2254 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2264 GNUNET_NO, no_handlers); 2255 GNUNET_NO, no_handlers);
2265 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2256 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2266} 2257}
2267 2258
@@ -2276,14 +2267,13 @@ handle_overlay_connect (void *cls,
2276 * iterate, 2267 * iterate,
2277 * GNUNET_NO if not. 2268 * GNUNET_NO if not.
2278 */ 2269 */
2279static int 2270static int
2280ss_map_free_iterator (void *cls, 2271ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
2281 const struct GNUNET_HashCode * key, void *value)
2282{ 2272{
2283 struct SharedService *ss = value; 2273 struct SharedService *ss = value;
2284 2274
2285 GNUNET_assert (GNUNET_YES == 2275 GNUNET_assert (GNUNET_YES ==
2286 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value)); 2276 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
2287 GNUNET_free (ss->name); 2277 GNUNET_free (ss->name);
2288 GNUNET_free (ss); 2278 GNUNET_free (ss);
2289 return GNUNET_YES; 2279 return GNUNET_YES;
@@ -2297,8 +2287,7 @@ ss_map_free_iterator (void *cls,
2297 * @param tc the TaskContext from scheduler 2287 * @param tc the TaskContext from scheduler
2298 */ 2288 */
2299static void 2289static void
2300shutdown_task (void *cls, 2290shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2301 const struct GNUNET_SCHEDULER_TaskContext *tc)
2302{ 2291{
2303 struct LCFContextQueue *lcfq; 2292 struct LCFContextQueue *lcfq;
2304 uint32_t id; 2293 uint32_t id;
@@ -2307,7 +2296,7 @@ shutdown_task (void *cls,
2307 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n"); 2296 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
2308 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator, 2297 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
2309 NULL); 2298 NULL);
2310 GNUNET_CONTAINER_multihashmap_destroy (ss_map); 2299 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
2311 if (NULL != lcfq_head) 2300 if (NULL != lcfq_head)
2312 { 2301 {
2313 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id) 2302 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
@@ -2331,10 +2320,10 @@ shutdown_task (void *cls,
2331 if (NULL != peer_list[id]) 2320 if (NULL != peer_list[id])
2332 { 2321 {
2333 if (GNUNET_NO == peer_list[id]->is_remote) 2322 if (GNUNET_NO == peer_list[id]->is_remote)
2334 { 2323 {
2335 GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer); 2324 GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
2336 GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg); 2325 GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
2337 } 2326 }
2338 GNUNET_free (peer_list[id]); 2327 GNUNET_free (peer_list[id]);
2339 } 2328 }
2340 GNUNET_free_non_null (peer_list); 2329 GNUNET_free_non_null (peer_list);
@@ -2353,12 +2342,12 @@ shutdown_task (void *cls,
2353 if (NULL != slave_list[id]) 2342 if (NULL != slave_list[id])
2354 { 2343 {
2355 if (NULL != slave_list[id]->controller) 2344 if (NULL != slave_list[id]->controller)
2356 GNUNET_TESTBED_controller_disconnect (slave_list[id]->controller); 2345 GNUNET_TESTBED_controller_disconnect (slave_list[id]->controller);
2357 if (NULL != slave_list[id]->controller_proc) 2346 if (NULL != slave_list[id]->controller_proc)
2358 GNUNET_TESTBED_controller_stop (slave_list[id]->controller_proc); 2347 GNUNET_TESTBED_controller_stop (slave_list[id]->controller_proc);
2359 } 2348 }
2360 if (NULL != master_context) 2349 if (NULL != master_context)
2361 { 2350 {
2362 GNUNET_free_non_null (master_context->master_ip); 2351 GNUNET_free_non_null (master_context->master_ip);
2363 if (NULL != master_context->system) 2352 if (NULL != master_context->system)
2364 GNUNET_TESTING_system_destroy (master_context->system, GNUNET_YES); 2353 GNUNET_TESTING_system_destroy (master_context->system, GNUNET_YES);
@@ -2384,10 +2373,10 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
2384 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n"); 2373 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
2385 GNUNET_SERVER_client_drop (client); 2374 GNUNET_SERVER_client_drop (client);
2386 /* should not be needed as we're terminated by failure to read 2375 /* should not be needed as we're terminated by failure to read
2387 from stdin, but if stdin fails for some reason, this shouldn't 2376 * from stdin, but if stdin fails for some reason, this shouldn't
2388 hurt for now --- might need to revise this later if we ever 2377 * hurt for now --- might need to revise this later if we ever
2389 decide that master connections might be temporarily down 2378 * decide that master connections might be temporarily down
2390 for some reason */ 2379 * for some reason */
2391 //GNUNET_SCHEDULER_shutdown (); 2380 //GNUNET_SCHEDULER_shutdown ();
2392 } 2381 }
2393} 2382}
@@ -2400,43 +2389,37 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
2400 * @param server the initialized server 2389 * @param server the initialized server
2401 * @param cfg configuration to use 2390 * @param cfg configuration to use
2402 */ 2391 */
2403static void 2392static void
2404testbed_run (void *cls, 2393testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
2405 struct GNUNET_SERVER_Handle *server,
2406 const struct GNUNET_CONFIGURATION_Handle *cfg) 2394 const struct GNUNET_CONFIGURATION_Handle *cfg)
2407{ 2395{
2408 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = 2396 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
2409 { 2397 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
2410 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0}, 2398 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
2411 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0}, 2399 {&handle_configure_shared_service, NULL,
2412 {&handle_configure_shared_service, NULL, 2400 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
2413 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0}, 2401 {&handle_link_controllers, NULL,
2414 {&handle_link_controllers, NULL, 2402 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
2415 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0}, 2403 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
2416 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0}, 2404 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER,
2417 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER, 2405 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
2418 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)}, 2406 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER,
2419 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER, 2407 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
2420 sizeof (struct GNUNET_TESTBED_PeerStartMessage)}, 2408 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER,
2421 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER, 2409 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
2422 sizeof (struct GNUNET_TESTBED_PeerStopMessage)}, 2410 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG,
2423 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG, 2411 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
2424 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)}, 2412 {&handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT,
2425 {&handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT, 2413 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
2426 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)}, 2414 {NULL}
2427 {NULL} 2415 };
2428 }; 2416
2429 2417 GNUNET_SERVER_add_handlers (server, message_handlers);
2430 GNUNET_SERVER_add_handlers (server, 2418 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
2431 message_handlers);
2432 GNUNET_SERVER_disconnect_notify (server,
2433 &client_disconnect_cb,
2434 NULL);
2435 ss_map = GNUNET_CONTAINER_multihashmap_create (5); 2419 ss_map = GNUNET_CONTAINER_multihashmap_create (5);
2436 shutdown_task_id = 2420 shutdown_task_id =
2437 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 2421 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2438 &shutdown_task, 2422 &shutdown_task, NULL);
2439 NULL);
2440 LOG_DEBUG ("Testbed startup complete\n"); 2423 LOG_DEBUG ("Testbed startup complete\n");
2441} 2424}
2442 2425
@@ -2444,15 +2427,11 @@ testbed_run (void *cls,
2444/** 2427/**
2445 * The starting point of execution 2428 * The starting point of execution
2446 */ 2429 */
2447int main (int argc, char *const *argv) 2430int
2431main (int argc, char *const *argv)
2448{ 2432{
2449 //sleep (15); /* Debugging */ 2433 //sleep (15); /* Debugging */
2450 return 2434 return (GNUNET_OK ==
2451 (GNUNET_OK == 2435 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
2452 GNUNET_SERVICE_run (argc, 2436 &testbed_run, NULL)) ? 0 : 1;
2453 argv,
2454 "testbed",
2455 GNUNET_SERVICE_OPTION_NONE,
2456 &testbed_run,
2457 NULL)) ? 0 : 1;
2458} 2437}