2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/gnunet-service-testbed.c
23 * @brief implementation of the TESTBED service
24 * @author Sree Harsha Totakura
28 #include "gnunet_service_lib.h"
29 #include "gnunet_server_lib.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_core_service.h"
32 #include "gnunet_hello_lib.h"
35 #include "gnunet_testbed_service.h"
37 #include "testbed_api.h"
38 #include "testbed_api_hosts.h"
39 #include "gnunet_testing_lib-new.h"
44 #define LOG(kind,...) \
45 GNUNET_log (kind, __VA_ARGS__)
50 #define LOG_DEBUG(...) \
51 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
54 * By how much should the arrays lists grow
56 #define LIST_GROW_STEP 10
59 * Default timeout for operations which may take some time
61 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
64 * The main context information associated with the client which started us
69 * The client handle associated with this context
71 struct GNUNET_SERVER_Client *client;
74 * The network address of the master controller
79 * The TESTING system handle for starting peers locally
81 struct GNUNET_TESTING_System *system;
84 * Event mask of event to be responded in this context
89 * Our host id according to this context
96 * The message queue for sending messages to clients
101 * The message to be sent
103 struct GNUNET_MessageHeader *msg;
106 * The client to send the message to
108 struct GNUNET_SERVER_Client *client;
111 * next pointer for DLL
113 struct MessageQueue *next;
116 * prev pointer for DLL
118 struct MessageQueue *prev;
123 * The structure for identifying a shared service
128 * The name of the shared service
133 * Number of shared peers per instance of the shared service
138 * Number of peers currently sharing the service
140 uint32_t num_sharing;
155 * The host destination is reachable thru
162 * Structure representing a connected(directly-linked) controller
167 * The controller process handle if we had started the controller
169 struct GNUNET_TESTBED_ControllerProc *controller_proc;
172 * The controller handle
174 struct GNUNET_TESTBED_Controller *controller;
177 * The id of the host this controller is running on
184 * States of LCFContext
189 * The Context has been initialized; Nothing has been done on it
194 * Delegated host has been registered at the forwarding controller
196 DELEGATED_HOST_REGISTERED,
199 * The slave host has been registred at the forwarding controller
201 SLAVE_HOST_REGISTERED,
204 * The context has been finished (may have error)
211 * Link controllers request forwarding context
216 * The gateway which will pass the link message to delegated host
218 struct Slave *gateway;
221 * The controller link message that has to be forwarded to
223 struct GNUNET_TESTBED_ControllerLinkMessage *msg;
226 * The client which has asked to perform this operation
228 struct GNUNET_SERVER_Client *client;
231 * The host registration handle while registered hosts in this context
233 struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
236 * The id of the operation which created this context
238 uint64_t operation_id;
241 * The state of this context
243 enum LCFContextState state;
248 uint32_t delegated_host_id;
253 uint32_t slave_host_id;
259 * Structure of a queue entry in LCFContext request queue
261 struct LCFContextQueue
266 struct LCFContext *lcf;
271 struct LCFContextQueue *next;
276 struct LCFContextQueue *prev;
281 * A locally started peer
290 * The peer handle from testing API
292 struct GNUNET_TESTING_Peer *peer;
295 * The modified (by GNUNET_TESTING_peer_configure) configuration this
296 * peer is configured with
298 struct GNUNET_CONFIGURATION_Handle *cfg;
301 * Is the peer running
310 * The controller this peer is started through
312 struct GNUNET_TESTBED_Controller *controller;
319 * Is this peer locally created?
324 * Our local reference id for this peer
332 * Context information for connecting 2 peers in overlay
334 struct OverlayConnectContext
337 * The client which has requested for overlay connection
339 struct GNUNET_SERVER_Client *client;
342 * the peer which has to connect to the other peer
349 struct Peer *other_peer;
352 * Transport handle of the first peer to get its HELLO
354 struct GNUNET_TRANSPORT_Handle *p1th;
357 * Transport handle of other peer to offer first peer's HELLO
359 struct GNUNET_TRANSPORT_Handle *p2th;
362 * Core handles of the first peer; used to notify when second peer connects to it
364 struct GNUNET_CORE_Handle *ch;
367 * HELLO of the other peer
369 struct GNUNET_MessageHeader *hello;
372 * Get hello handle to acquire HELLO of first peer
374 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
377 * The error message we send if this overlay connect operation has timed out
382 * The peer identity of the first peer
384 struct GNUNET_PeerIdentity peer_identity;
387 * The peer identity of the other peer
389 struct GNUNET_PeerIdentity other_peer_identity;
392 * The id of the operation responsible for creating this context
397 * The id of the task for sending HELLO of peer 2 to peer 1 and ask peer 1 to
400 GNUNET_SCHEDULER_TaskIdentifier send_hello_task;
403 * The id of the overlay connect timeout task
405 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
411 * Context information for operations forwarded to subcontrollers
413 struct ForwardedOperationContext
416 * The generated operation context
418 struct OperationContext *opc;
421 * The client to which we have to reply
423 struct GNUNET_SERVER_Client *client;
431 * Task ID for the timeout task
433 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
436 * The id of the operation that has been forwarded
438 uint64_t operation_id;
444 * Context information used while linking controllers
446 struct LinkControllersContext
449 * The client which initiated the link controller operation
451 struct GNUNET_SERVER_Client *client;
454 * The ID of the operation
456 uint64_t operation_id;
459 * Pointer to the slave handle if we are directly starting/connecting to the controller
467 * The master context; generated with the first INIT message
469 static struct Context *master_context;
476 * Current Transmit Handle; NULL if no notify transmit exists currently
478 static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
485 * The head for the LCF queue
487 static struct LCFContextQueue *lcfq_head;
490 * The tail for the LCF queue
492 static struct LCFContextQueue *lcfq_tail;
495 * The message queue head
497 static struct MessageQueue *mq_head;
500 * The message queue tail
502 static struct MessageQueue *mq_tail;
507 static struct GNUNET_TESTBED_Host **host_list;
512 static struct Route **route_list;
515 * A list of directly linked neighbours
517 static struct Slave **slave_list;
520 * A list of peers we own locally
522 static struct Peer **peer_list;
525 * The hashmap of shared services
527 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
530 * The size of the host list
532 static uint32_t host_list_size;
535 * The size of the route list
537 static uint32_t route_list_size;
540 * The size of directly linked neighbours list
542 static uint32_t slave_list_size;
545 * The size of the peer list
547 static uint32_t peer_list_size;
554 * The lcf_task handle
556 static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
559 * The shutdown task handle
561 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
565 * Function called to notify a client about the connection begin ready to queue
566 * more data. "buf" will be NULL and "size" zero if the connection was closed
567 * for writing in the meantime.
570 * @param size number of bytes available in buf
571 * @param buf where the callee should write the message
572 * @return number of bytes written to buf
575 transmit_ready_notify (void *cls, size_t size, void *buf)
577 struct MessageQueue *mq_entry;
579 transmit_handle = NULL;
581 GNUNET_assert (NULL != mq_entry);
584 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
585 size = ntohs (mq_entry->msg->size);
586 memcpy (buf, mq_entry->msg, size);
587 GNUNET_free (mq_entry->msg);
588 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
589 GNUNET_free (mq_entry);
591 if (NULL != mq_entry)
593 GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
594 ntohs (mq_entry->msg->size),
595 GNUNET_TIME_UNIT_FOREVER_REL,
596 &transmit_ready_notify, NULL);
602 * Queues a message in send queue for sending to the service
604 * @param client the client to whom the queued message has to be sent
605 * @param msg the message to queue
608 queue_message (struct GNUNET_SERVER_Client *client,
609 struct GNUNET_MessageHeader *msg)
611 struct MessageQueue *mq_entry;
615 type = ntohs (msg->type);
616 size = ntohs (msg->size);
617 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
618 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
619 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
621 mq_entry->client = client;
622 LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type,
624 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
625 if (NULL == transmit_handle)
627 GNUNET_SERVER_notify_transmit_ready (client, size,
628 GNUNET_TIME_UNIT_FOREVER_REL,
629 &transmit_ready_notify, NULL);
634 * Similar to GNUNET_realloc; however clears tail part of newly allocated memory
636 * @param ptr the memory block to realloc
637 * @param size the size of ptr
638 * @param new_size the size to which ptr has to be realloc'ed
639 * @return the newly reallocated memory block
642 TESTBED_realloc (void *ptr, size_t size, size_t new_size)
644 ptr = GNUNET_realloc (ptr, new_size);
646 ptr = memset (ptr + size, 0, new_size - size);
652 * Function to add a host to the current list of known hosts
654 * @param host the host to add
655 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
659 host_list_add (struct GNUNET_TESTBED_Host *host)
663 host_id = GNUNET_TESTBED_host_get_id_ (host);
664 if (host_list_size <= host_id)
667 TESTBED_realloc (host_list,
668 sizeof (struct GNUNET_TESTBED_Host *) * host_list_size,
669 sizeof (struct GNUNET_TESTBED_Host *) *
670 (host_list_size + LIST_GROW_STEP));
671 host_list_size += LIST_GROW_STEP;
673 if (NULL != host_list[host_id])
675 LOG_DEBUG ("A host with id: %u already exists\n", host_id);
676 return GNUNET_SYSERR;
678 host_list[host_id] = host;
684 * Adds a route to the route list
686 * @param route the route to add
689 route_list_add (struct Route *route)
691 if (route->dest >= route_list_size)
694 TESTBED_realloc (route_list, sizeof (struct Route *) * route_list_size,
695 sizeof (struct Route *) * (route_list_size +
697 route_list_size += LIST_GROW_STEP;
699 GNUNET_assert (NULL == route_list[route->dest]);
700 route_list[route->dest] = route;
705 * Adds a slave to the slave array
707 * @param slave the slave controller to add
710 slave_list_add (struct Slave *slave)
712 if (slave->host_id >= slave_list_size)
715 TESTBED_realloc (slave_list, sizeof (struct Slave *) * slave_list_size,
716 sizeof (struct Slave *) * (slave_list_size +
718 slave_list_size += LIST_GROW_STEP;
720 GNUNET_assert (NULL == slave_list[slave->host_id]);
721 slave_list[slave->host_id] = slave;
726 * Adds a peer to the peer array
728 * @param peer the peer to add
731 peer_list_add (struct Peer *peer)
735 orig_size = peer_list_size;
736 if (peer->id >= peer_list_size)
738 while (peer->id >= peer_list_size)
739 peer_list_size += LIST_GROW_STEP;
741 TESTBED_realloc (peer_list, sizeof (struct Peer *) * orig_size,
742 sizeof (struct Peer *) * peer_list_size);
744 GNUNET_assert (NULL == peer_list[peer->id]);
745 peer_list[peer->id] = peer;
750 * Removes a the give peer from the peer array
752 * @param peer the peer to be removed
755 peer_list_remove (struct Peer *peer)
760 peer_list[peer->id] = NULL;
761 orig_size = peer_list_size;
762 while (peer_list_size >= LIST_GROW_STEP)
764 for (id = peer_list_size - 1;
765 (id >= peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); id--)
766 if (NULL != peer_list[id])
768 if (id != ((peer_list_size - LIST_GROW_STEP) - 1))
770 peer_list_size -= LIST_GROW_STEP;
772 if (orig_size == peer_list_size)
775 GNUNET_realloc (peer_list, sizeof (struct Peer *) * peer_list_size);
780 * Finds the route with directly connected host as destination through which
781 * the destination host can be reached
783 * @param host_id the id of the destination host
784 * @return the route with directly connected destination host; NULL if no route
787 static struct Route *
788 find_dest_route (uint32_t host_id)
792 while (NULL != (route = route_list[host_id]))
794 if (route->thru == master_context->host_id)
796 host_id = route->thru;
803 * Routes message to a host given its host_id
805 * @param host_id the id of the destination host
806 * @param msg the message to be routed
809 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
816 * Send operation failure message to client
818 * @param client the client to which the failure message has to be sent to
819 * @param operation_id the id of the failed operation
820 * @param emsg the error message; can be NULL
823 send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
824 uint64_t operation_id, const char *emsg)
826 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
830 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
831 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
833 msg = GNUNET_malloc (msize);
834 msg->header.size = htons (msize);
835 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONFAILEVENT);
836 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
837 msg->operation_id = GNUNET_htonll (operation_id);
839 memcpy (&msg[1], emsg, emsg_len);
840 queue_message (client, &msg->header);
845 * Function to send generic operation success message to given client
847 * @param client the client to send the message to
848 * @param operation_id the id of the operation which was successful
851 send_operation_success_msg (struct GNUNET_SERVER_Client *client,
852 uint64_t operation_id)
854 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
857 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
858 msg = GNUNET_malloc (msize);
859 msg->header.size = htons (msize);
860 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
861 msg->operation_id = GNUNET_htonll (operation_id);
862 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
863 queue_message (client, &msg->header);
868 * The Link Controller forwarding task
870 * @param cls the LCFContext
871 * @param tc the Task context from scheduler
874 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
878 * Completion callback for host registrations while forwarding Link Controller messages
880 * @param cls the LCFContext
881 * @param emsg the error message; NULL if host registration is successful
884 lcf_proc_cc (void *cls, const char *emsg)
886 struct LCFContext *lcf = cls;
889 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
894 goto registration_error;
895 lcf->state = DELEGATED_HOST_REGISTERED;
896 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
898 case DELEGATED_HOST_REGISTERED:
900 goto registration_error;
901 lcf->state = SLAVE_HOST_REGISTERED;
902 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
905 GNUNET_assert (0); /* Shouldn't reach here */
910 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
912 lcf->state = FINISHED;
913 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
918 * Callback to be called when forwarded link controllers operation is
919 * successfull. We have to relay the reply msg back to the client
921 * @param cls ForwardedOperationContext
922 * @param msg the peer create success message
925 forwarded_operation_reply_relay (void *cls,
926 const struct GNUNET_MessageHeader *msg)
928 struct ForwardedOperationContext *fopc = cls;
929 struct GNUNET_MessageHeader *dup_msg;
932 msize = ntohs (msg->size);
933 dup_msg = GNUNET_malloc (msize);
934 (void) memcpy (dup_msg, msg, msize);
935 queue_message (fopc->client, dup_msg);
936 GNUNET_SERVER_client_drop (fopc->client);
937 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
943 * Task to free resources when forwarded link controllers has been timedout
945 * @param cls the ForwardedOperationContext
946 * @param tc the task context from scheduler
949 forwarded_operation_timeout (void *cls,
950 const struct GNUNET_SCHEDULER_TaskContext *tc)
952 struct ForwardedOperationContext *fopc = cls;
954 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
955 send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
956 GNUNET_SERVER_client_drop (fopc->client);
962 * The Link Controller forwarding task
964 * @param cls the LCFContext
965 * @param tc the Task context from scheduler
968 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
970 struct LCFContext *lcf = cls;
971 struct LCFContextQueue *lcfq;
972 struct ForwardedOperationContext *fopc;
974 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
979 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id],
980 lcf->gateway->controller))
983 GNUNET_TESTBED_register_host (lcf->gateway->controller,
984 host_list[lcf->delegated_host_id],
989 lcf->state = DELEGATED_HOST_REGISTERED;
990 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
993 case DELEGATED_HOST_REGISTERED:
995 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id],
996 lcf->gateway->controller))
999 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1000 host_list[lcf->slave_host_id],
1005 lcf->state = SLAVE_HOST_REGISTERED;
1006 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1009 case SLAVE_HOST_REGISTERED:
1010 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1011 fopc->client = lcf->client;
1012 fopc->operation_id = lcf->operation_id;
1014 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
1017 &forwarded_operation_reply_relay,
1019 fopc->timeout_task =
1020 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1022 lcf->state = FINISHED;
1023 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1027 GNUNET_assert (lcfq->lcf == lcf);
1028 GNUNET_free (lcf->msg);
1030 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
1032 if (NULL != lcfq_head)
1034 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
1040 * Callback for event from slave controllers
1042 * @param cls struct Slave *
1043 * @param event information about the event
1046 slave_event_callback (void *cls,
1047 const struct GNUNET_TESTBED_EventInformation *event)
1054 * Callback to signal successfull startup of the controller process
1056 * @param cls the closure from GNUNET_TESTBED_controller_start()
1057 * @param cfg the configuration with which the controller has been started;
1058 * NULL if status is not GNUNET_OK
1059 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
1060 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1063 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
1066 struct LinkControllersContext *lcc = cls;
1068 if (GNUNET_SYSERR == status)
1070 lcc->slave->controller_proc = NULL;
1071 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
1072 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
1075 lcc->slave->controller =
1076 GNUNET_TESTBED_controller_connect (cfg, host_list[lcc->slave->host_id],
1077 master_context->event_mask,
1078 &slave_event_callback, lcc->slave);
1079 if (NULL != lcc->slave->controller)
1080 send_operation_success_msg (lcc->client, lcc->operation_id);
1082 send_operation_fail_msg (lcc->client, lcc->operation_id,
1083 "Could not connect to delegated controller");
1084 GNUNET_SERVER_client_drop (lcc->client);
1090 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
1093 * @param client identification of the client
1094 * @param message the actual message
1097 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
1098 const struct GNUNET_MessageHeader *message)
1100 const struct GNUNET_TESTBED_InitMessage *msg;
1101 struct GNUNET_TESTBED_Host *host;
1102 const char *controller_hostname;
1105 if (NULL != master_context)
1108 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1111 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
1112 msize = ntohs (message->size);
1113 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
1116 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1119 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
1120 controller_hostname = (const char *) &msg[1];
1121 if ('\0' != controller_hostname[msize - 1])
1124 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1127 master_context = GNUNET_malloc (sizeof (struct Context));
1128 master_context->client = client;
1129 master_context->host_id = ntohl (msg->host_id);
1130 master_context->master_ip = GNUNET_strdup (controller_hostname);
1131 LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip);
1132 master_context->system =
1133 GNUNET_TESTING_system_create ("testbed", master_context->master_ip);
1135 GNUNET_TESTBED_host_create_with_id (master_context->host_id, NULL, NULL,
1137 host_list_add (host);
1138 master_context->event_mask = GNUNET_ntohll (msg->event_mask);
1139 GNUNET_SERVER_client_keep (client);
1140 LOG_DEBUG ("Created master context with host ID: %u\n",
1141 master_context->host_id);
1142 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1147 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1150 * @param client identification of the client
1151 * @param message the actual message
1154 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
1155 const struct GNUNET_MessageHeader *message)
1157 struct GNUNET_TESTBED_Host *host;
1158 const struct GNUNET_TESTBED_AddHostMessage *msg;
1159 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
1164 uint16_t username_length;
1165 uint16_t hostname_length;
1166 uint16_t reply_size;
1169 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
1170 msize = ntohs (msg->header.size);
1171 username = (char *) &(msg[1]);
1172 username_length = ntohs (msg->user_name_length);
1173 GNUNET_assert (msize > (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length + 1)); /* msg must contain hostname */
1174 if (0 != username_length)
1175 GNUNET_assert ('\0' == username[username_length]);
1176 username_length = (0 == username_length) ? 0 : username_length + 1;
1177 hostname = username + username_length;
1179 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
1180 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
1181 GNUNET_assert (strlen (hostname) == hostname_length - 1);
1182 host_id = ntohl (msg->host_id);
1183 LOG_DEBUG ("Received ADDHOST message\n");
1184 LOG_DEBUG ("-------host id: %u\n", host_id);
1185 if (NULL != hostname)
1186 LOG_DEBUG ("-------hostname: %s\n", hostname);
1187 if (0 != username_length)
1188 LOG_DEBUG ("-------username: %s\n", username);
1191 LOG_DEBUG ("-------username: NULL\n");
1194 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1196 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1197 ntohs (msg->ssh_port));
1198 GNUNET_assert (NULL != host);
1199 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1200 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1201 if (GNUNET_OK != host_list_add (host))
1203 /* We are unable to add a host */
1204 emsg = "A host exists with given host-id";
1205 LOG_DEBUG ("%s: %u", emsg, host_id);
1206 GNUNET_TESTBED_host_destroy (host);
1207 reply_size += strlen (emsg) + 1;
1208 reply = GNUNET_malloc (reply_size);
1209 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1212 reply = GNUNET_malloc (reply_size);
1213 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
1214 reply->header.size = htons (reply_size);
1215 reply->host_id = htonl (host_id);
1216 queue_message (client, &reply->header);
1221 * Iterator over hash map entries.
1223 * @param cls closure
1224 * @param key current key code
1225 * @param value value in the hash map
1226 * @return GNUNET_YES if we should continue to
1231 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1233 struct SharedService *queried_ss = cls;
1234 struct SharedService *ss = value;
1236 if (0 == strcmp (ss->name, queried_ss->name))
1244 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1247 * @param client identification of the client
1248 * @param message the actual message
1251 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1252 const struct GNUNET_MessageHeader *message)
1254 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1255 struct SharedService *ss;
1257 struct GNUNET_HashCode hash;
1259 uint16_t service_name_size;
1261 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1262 msg_size = ntohs (message->size);
1263 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1266 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1270 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1271 service_name = (char *) &msg[1];
1272 if ('\0' != service_name[service_name_size - 1])
1275 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1278 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1279 service_name, ntohl (msg->num_peers));
1280 if (ntohl (msg->host_id) != master_context->host_id)
1282 route_message (ntohl (msg->host_id), message);
1283 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1286 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1287 ss = GNUNET_malloc (sizeof (struct SharedService));
1288 ss->name = strdup (service_name);
1289 ss->num_shared = ntohl (msg->num_peers);
1290 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1291 if (GNUNET_SYSERR ==
1292 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1293 &ss_exists_iterator, ss))
1295 LOG (GNUNET_ERROR_TYPE_WARNING,
1296 "Service %s already configured as a shared service. "
1297 "Ignoring service sharing request \n", ss->name);
1298 GNUNET_free (ss->name);
1302 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1303 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1308 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1311 * @param client identification of the client
1312 * @param message the actual message
1315 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1316 const struct GNUNET_MessageHeader *message)
1318 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1319 struct GNUNET_CONFIGURATION_Handle *cfg;
1320 struct LCFContextQueue *lcfq;
1321 struct Route *route;
1322 struct Route *new_route;
1326 uint32_t delegated_host_id;
1327 uint32_t slave_host_id;
1330 if (NULL == master_context)
1333 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1336 msize = ntohs (message->size);
1337 if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
1340 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1343 msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
1344 delegated_host_id = ntohl (msg->delegated_host_id);
1345 if (delegated_host_id == master_context->host_id)
1348 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1349 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1352 if ((delegated_host_id >= host_list_size) ||
1353 (NULL == host_list[delegated_host_id]))
1355 LOG (GNUNET_ERROR_TYPE_WARNING, "Delegated host not registered with us\n");
1356 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1359 slave_host_id = ntohl (msg->slave_host_id);
1360 if ((slave_host_id >= host_list_size) || (NULL == host_list[slave_host_id]))
1362 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host not registered with us\n");
1363 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1366 if (slave_host_id == delegated_host_id)
1368 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1369 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1373 if (slave_host_id == master_context->host_id) /* Link from us */
1375 struct Slave *slave;
1376 struct LinkControllersContext *lcc;
1378 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1379 config_size = ntohs (msg->config_size);
1380 if ((delegated_host_id < slave_list_size) && (NULL != slave_list[delegated_host_id])) /* We have already added */
1382 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1384 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1387 config = GNUNET_malloc (config_size);
1388 dest_size = (uLongf) config_size;
1390 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1393 GNUNET_break (0); /* Compression error */
1394 GNUNET_free (config);
1395 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1398 if (config_size != dest_size)
1400 LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1401 GNUNET_free (config);
1402 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1405 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1407 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1409 GNUNET_break (0); /* Configuration parsing error */
1410 GNUNET_free (config);
1411 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1414 GNUNET_free (config);
1415 if ((delegated_host_id < slave_list_size) &&
1416 (NULL != slave_list[delegated_host_id]))
1418 GNUNET_break (0); /* Configuration parsing error */
1419 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1422 slave = GNUNET_malloc (sizeof (struct Slave));
1423 slave->host_id = delegated_host_id;
1424 slave_list_add (slave);
1425 if (1 != msg->is_subordinate)
1428 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1429 master_context->event_mask,
1430 &slave_event_callback, slave);
1431 GNUNET_CONFIGURATION_destroy (cfg);
1432 if (NULL != slave->controller)
1433 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1435 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1436 "Could not connect to delegated controller");
1437 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1440 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1441 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1442 GNUNET_SERVER_client_keep (client);
1443 lcc->client = client;
1445 slave->controller_proc =
1446 GNUNET_TESTBED_controller_start (master_context->master_ip,
1447 host_list[slave->host_id], cfg,
1448 &slave_status_callback, lcc);
1449 GNUNET_CONFIGURATION_destroy (cfg);
1450 new_route = GNUNET_malloc (sizeof (struct Route));
1451 new_route->dest = delegated_host_id;
1452 new_route->thru = master_context->host_id;
1453 route_list_add (new_route);
1454 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1458 /* Route the request */
1459 if (slave_host_id >= route_list_size)
1461 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1462 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1465 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1466 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1467 lcfq->lcf->delegated_host_id = delegated_host_id;
1468 lcfq->lcf->slave_host_id = slave_host_id;
1469 route = find_dest_route (slave_host_id);
1470 GNUNET_assert (NULL != route); /* because we add routes carefully */
1471 GNUNET_assert (route->dest < slave_list_size);
1472 GNUNET_assert (NULL != slave_list[route->dest]);
1473 lcfq->lcf->state = INIT;
1474 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1475 lcfq->lcf->gateway = slave_list[route->dest];
1476 lcfq->lcf->msg = GNUNET_malloc (msize);
1477 (void) memcpy (lcfq->lcf->msg, msg, msize);
1478 GNUNET_SERVER_client_keep (client);
1479 lcfq->lcf->client = client;
1480 if (NULL == lcfq_head)
1482 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1483 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1484 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1487 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1488 /* FIXME: Adding a new route should happen after the controllers are linked
1490 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1491 new_route = GNUNET_malloc (sizeof (struct Route));
1492 new_route->dest = delegated_host_id;
1493 new_route->thru = route->dest;
1494 route_list_add (new_route);
1499 * The task to be executed if the forwarded peer create operation has been
1502 * @param cls the FowardedOperationContext
1503 * @param tc the TaskContext from the scheduler
1506 peer_create_forward_timeout (void *cls,
1507 const struct GNUNET_SCHEDULER_TaskContext *tc)
1509 struct ForwardedOperationContext *fo_ctxt = cls;
1511 /* send error msg to client */
1512 send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, "Timedout");
1513 GNUNET_SERVER_client_drop (fo_ctxt->client);
1514 GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc);
1515 GNUNET_free (fo_ctxt);
1520 * Callback to be called when forwarded peer create operation is
1521 * successfull. We have to relay the reply msg back to the client
1523 * @param cls ForwardedOperationContext
1524 * @param msg the peer create success message
1527 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1529 struct ForwardedOperationContext *fo_ctxt = cls;
1530 const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *success_msg;
1531 struct GNUNET_MessageHeader *dup_msg;
1535 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);
1536 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
1539 (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *) msg;
1540 peer = GNUNET_malloc (sizeof (struct Peer));
1541 peer->is_remote = GNUNET_YES;
1542 peer->id = ntohl (success_msg->peer_id);
1543 GNUNET_assert (NULL != fo_ctxt->cls);
1544 peer->details.remote.controller = fo_ctxt->cls;
1545 peer_list_add (peer);
1547 msize = ntohs (msg->size);
1548 dup_msg = GNUNET_malloc (msize);
1549 (void) memcpy (dup_msg, msg, msize);
1550 queue_message (fo_ctxt->client, dup_msg);
1551 GNUNET_SERVER_client_drop (fo_ctxt->client);
1552 GNUNET_free (fo_ctxt);
1558 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1561 * @param client identification of the client
1562 * @param message the actual message
1565 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1566 const struct GNUNET_MessageHeader *message)
1568 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1569 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1570 struct GNUNET_CONFIGURATION_Handle *cfg;
1571 struct ForwardedOperationContext *fo_ctxt;
1572 struct Route *route;
1577 uint32_t config_size;
1583 msize = ntohs (message->size);
1584 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1586 GNUNET_break (0); /* We need configuration */
1587 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1590 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1591 host_id = ntohl (msg->host_id);
1592 peer_id = ntohl (msg->peer_id);
1593 if (UINT32_MAX == peer_id)
1595 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1596 "Cannot create peer with given ID");
1597 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1600 if (host_id == master_context->host_id)
1604 /* We are responsible for this peer */
1605 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1606 config_size = ntohl (msg->config_size);
1607 config = GNUNET_malloc (config_size);
1608 dest_size = config_size;
1611 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1612 (const Bytef *) &msg[1], (uLong) msize)))
1614 GNUNET_break (0); /* uncompression error */
1615 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1618 if (config_size != dest_size)
1620 GNUNET_break (0); /* Uncompressed config size mismatch */
1621 GNUNET_free (config);
1622 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1625 cfg = GNUNET_CONFIGURATION_create ();
1627 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1629 GNUNET_break (0); /* Configuration parsing error */
1630 GNUNET_free (config);
1631 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1634 GNUNET_free (config);
1635 peer = GNUNET_malloc (sizeof (struct Peer));
1636 peer->is_remote = GNUNET_NO;
1637 peer->details.local.cfg = cfg;
1639 LOG_DEBUG ("Creating peer with id: %u\n", peer->id);
1640 peer->details.local.peer =
1641 GNUNET_TESTING_peer_configure (master_context->system,
1642 peer->details.local.cfg, peer->id,
1643 NULL /* Peer id */ ,
1645 if (NULL == peer->details.local.peer)
1647 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1651 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1654 peer->details.local.is_running = GNUNET_NO;
1655 peer_list_add (peer);
1657 GNUNET_malloc (sizeof
1658 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1659 reply->header.size =
1660 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1661 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
1662 reply->peer_id = msg->peer_id;
1663 reply->operation_id = msg->operation_id;
1664 queue_message (client, &reply->header);
1665 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1669 /* Forward peer create request */
1670 route = find_dest_route (host_id);
1674 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1677 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1678 GNUNET_SERVER_client_keep (client);
1679 fo_ctxt->client = client;
1680 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1681 fo_ctxt->cls = slave_list[route->dest]->controller;
1683 GNUNET_TESTBED_forward_operation_msg_ (slave_list
1684 [route->dest]->controller,
1685 fo_ctxt->operation_id,
1687 peer_create_success_cb, fo_ctxt);
1688 fo_ctxt->timeout_task =
1689 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
1692 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1697 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1700 * @param client identification of the client
1701 * @param message the actual message
1704 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
1705 const struct GNUNET_MessageHeader *message)
1707 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1708 struct ForwardedOperationContext *fopc;
1712 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1713 peer_id = ntohl (msg->peer_id);
1714 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1715 peer_id, GNUNET_ntohll (msg->operation_id));
1716 if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id]))
1718 LOG (GNUNET_ERROR_TYPE_ERROR,
1719 "Asked to destroy a non existent peer with id: %u\n", peer_id);
1720 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1721 "Peer doesn't exist");
1722 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1725 peer = peer_list[peer_id];
1726 if (GNUNET_YES == peer->is_remote)
1728 /* Forward the destory message to sub controller */
1729 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1730 GNUNET_SERVER_client_keep (client);
1731 fopc->client = client;
1732 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1734 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
1735 fopc->operation_id, &msg->header,
1736 &forwarded_operation_reply_relay,
1738 fopc->timeout_task =
1739 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1741 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1744 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1745 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
1746 peer_list_remove (peer);
1748 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1749 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1754 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1757 * @param client identification of the client
1758 * @param message the actual message
1761 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
1762 const struct GNUNET_MessageHeader *message)
1764 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1765 struct GNUNET_TESTBED_PeerEventMessage *reply;
1766 struct ForwardedOperationContext *fopc;
1770 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
1771 peer_id = ntohl (msg->peer_id);
1772 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
1775 LOG (GNUNET_ERROR_TYPE_ERROR,
1776 "Asked to start a non existent peer with id: %u\n", peer_id);
1777 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1780 peer = peer_list[peer_id];
1781 if (GNUNET_YES == peer->is_remote)
1783 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1784 GNUNET_SERVER_client_keep (client);
1785 fopc->client = client;
1786 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1788 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
1789 fopc->operation_id, &msg->header,
1790 &forwarded_operation_reply_relay,
1792 fopc->timeout_task =
1793 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1795 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1798 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
1800 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1802 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1805 peer->details.local.is_running = GNUNET_YES;
1806 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1807 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
1808 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1809 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
1810 reply->host_id = htonl (master_context->host_id);
1811 reply->peer_id = msg->peer_id;
1812 reply->operation_id = msg->operation_id;
1813 queue_message (client, &reply->header);
1814 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1819 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1822 * @param client identification of the client
1823 * @param message the actual message
1826 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
1827 const struct GNUNET_MessageHeader *message)
1829 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1830 struct GNUNET_TESTBED_PeerEventMessage *reply;
1831 struct ForwardedOperationContext *fopc;
1835 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
1836 peer_id = ntohl (msg->peer_id);
1837 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
1839 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1841 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1844 peer = peer_list[peer_id];
1845 if (GNUNET_YES == peer->is_remote)
1847 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1848 GNUNET_SERVER_client_keep (client);
1849 fopc->client = client;
1850 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1852 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
1853 fopc->operation_id, &msg->header,
1854 &forwarded_operation_reply_relay,
1856 fopc->timeout_task =
1857 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1859 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1862 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer->details.local.peer))
1864 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1865 "Peer not running");
1866 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1869 peer->details.local.is_running = GNUNET_NO;
1870 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1871 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
1872 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1873 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
1874 reply->host_id = htonl (master_context->host_id);
1875 reply->peer_id = msg->peer_id;
1876 reply->operation_id = msg->operation_id;
1877 queue_message (client, &reply->header);
1878 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1883 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
1886 * @param client identification of the client
1887 * @param message the actual message
1890 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1891 const struct GNUNET_MessageHeader *message)
1893 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
1894 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
1903 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
1904 peer_id = ntohl (msg->peer_id);
1905 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
1907 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1909 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1912 peer = peer_list[peer_id];
1913 if (GNUNET_YES == peer->is_remote)
1915 /* FIXME: forward to sub controller */
1917 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1921 GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->details.local.cfg,
1923 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
1924 GNUNET_free (config);
1927 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1928 reply = GNUNET_realloc (xconfig, msize);
1929 (void) memmove (&reply[1], reply, xc_size);
1930 reply->header.size = htons (msize);
1931 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG);
1932 reply->peer_id = msg->peer_id;
1933 reply->operation_id = msg->operation_id;
1934 GNUNET_TESTING_peer_get_identity (peer_list[peer_id]->details.local.peer,
1935 &reply->peer_identity);
1936 reply->config_size = htons ((uint16_t) c_size);
1937 queue_message (client, &reply->header);
1938 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1943 * Task for cleaing up overlay connect context structure
1945 * @param cls the overlay connect context
1946 * @param tc the task context
1949 occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1951 struct OverlayConnectContext *occ = cls;
1953 LOG_DEBUG ("Cleaning up occ\n");
1954 GNUNET_free_non_null (occ->emsg);
1955 GNUNET_free_non_null (occ->hello);
1956 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
1957 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
1958 if (NULL != occ->ch)
1959 GNUNET_CORE_disconnect (occ->ch);
1960 if (NULL != occ->ghh)
1961 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
1962 if (NULL != occ->p1th)
1963 GNUNET_TRANSPORT_disconnect (occ->p1th);
1964 if (NULL != occ->p2th)
1965 GNUNET_TRANSPORT_disconnect (occ->p2th);
1971 * Task which will be run when overlay connect request has been timed out
1973 * @param cls the OverlayConnectContext
1974 * @param tc the TaskContext
1977 timeout_overlay_connect (void *cls,
1978 const struct GNUNET_SCHEDULER_TaskContext *tc)
1980 struct OverlayConnectContext *occ = cls;
1982 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1983 send_operation_fail_msg (occ->client, occ->op_id, occ->emsg);
1984 GNUNET_SERVER_client_drop (occ->client);
1985 occ_cleanup (occ, tc);
1991 * Function called to notify transport users that another
1992 * peer connected to us.
1994 * @param cls closure
1995 * @param new_peer the peer that connected
1996 * @param ats performance data
1997 * @param ats_count number of entries in ats (excluding 0-termination)
2000 overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2001 const struct GNUNET_ATS_Information *ats,
2002 unsigned int ats_count)
2004 struct OverlayConnectContext *occ = cls;
2005 struct GNUNET_TESTBED_ConnectionEventMessage *msg;
2007 char *other_peer_str;
2009 LOG_DEBUG ("Overlay connect notify\n");
2011 memcmp (new_peer, &occ->peer_identity,
2012 sizeof (struct GNUNET_PeerIdentity)))
2014 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer));
2015 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2017 memcmp (new_peer, &occ->other_peer_identity,
2018 sizeof (struct GNUNET_PeerIdentity)))
2020 LOG_DEBUG ("Unexpected peer %4s connected when expecting peer %4s\n",
2021 new_peer_str, other_peer_str);
2022 GNUNET_free (new_peer_str);
2023 GNUNET_free (other_peer_str);
2026 GNUNET_free (new_peer_str);
2027 LOG_DEBUG ("Peer %4s connected to peer %4s\n", other_peer_str,
2028 GNUNET_i2s (&occ->peer_identity));
2029 GNUNET_free (other_peer_str);
2030 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2032 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2033 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2035 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
2036 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2037 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2038 GNUNET_free_non_null (occ->emsg);
2040 if (NULL != occ->p2th)
2041 GNUNET_TRANSPORT_disconnect (occ->p2th);
2043 LOG_DEBUG ("Peers connected - Sending overlay connect success\n");
2044 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2046 htons (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2047 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT);
2048 msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
2049 msg->peer1 = htonl (occ->peer->id);
2050 msg->peer2 = htonl (occ->other_peer->id);
2051 msg->operation_id = GNUNET_htonll (occ->op_id);
2052 queue_message (occ->client, &msg->header);
2053 GNUNET_SERVER_client_drop (occ->client);
2054 GNUNET_SCHEDULER_add_now (&occ_cleanup, occ);
2059 * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to
2062 * @param cls the OverlayConnectContext
2063 * @param tc the TaskContext from scheduler
2066 send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2068 struct OverlayConnectContext *occ = cls;
2069 char *other_peer_str;
2071 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2072 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2074 GNUNET_assert (NULL != occ->hello);
2075 if (GNUNET_YES == occ->other_peer->is_remote)
2077 struct GNUNET_TESTBED_RequestConnectMessage *msg;
2079 uint16_t hello_size;
2081 hello_size = ntohs (occ->hello->size);
2082 msize = sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hello_size;
2083 msg = GNUNET_malloc (msize);
2084 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT);
2085 msg->header.size = htons (msize);
2086 msg->peer = htonl (occ->peer->id);
2087 msg->operation_id = GNUNET_htonll (occ->op_id);
2088 (void) memcpy (&msg->peer_identity, &occ->peer_identity,
2089 sizeof (struct GNUNET_PeerIdentity));
2090 memcpy (msg->hello, occ->hello, hello_size);
2091 GNUNET_TESTBED_queue_message_ (occ->other_peer->details.remote.controller,
2096 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2097 LOG_DEBUG ("Offering HELLO of %s to %s\n",
2098 GNUNET_i2s (&occ->peer_identity), other_peer_str);
2099 GNUNET_free (other_peer_str);
2100 GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL);
2101 GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity);
2103 occ->send_hello_task =
2104 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &send_hello, occ);
2108 * Test for checking whether HELLO message is empty
2110 * @param cls empty flag to set
2111 * @param address the HELLO
2112 * @param expiration expiration of the HELLO
2116 test_address (void *cls, const struct GNUNET_HELLO_Address *address,
2117 struct GNUNET_TIME_Absolute expiration)
2127 * Function called whenever there is an update to the
2128 * HELLO of peers in the OverlayConnectClosure
2130 * @param cls closure
2131 * @param hello our updated HELLO
2134 hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2136 struct OverlayConnectContext *occ = cls;
2140 msize = ntohs (hello->size);
2142 (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *)
2143 hello, GNUNET_NO, &test_address,
2145 if (GNUNET_YES == empty)
2147 LOG_DEBUG ("HELLO of %s is empty\n", GNUNET_i2s (&occ->peer_identity));
2150 LOG_DEBUG ("Received HELLO of %s\n", GNUNET_i2s (&occ->peer_identity));
2151 occ->hello = GNUNET_malloc (msize);
2152 memcpy (occ->hello, hello, msize);
2153 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2155 GNUNET_TRANSPORT_disconnect (occ->p1th);
2157 GNUNET_free_non_null (occ->emsg);
2158 if (GNUNET_NO == occ->other_peer->is_remote)
2161 GNUNET_TRANSPORT_connect (occ->other_peer->details.local.cfg,
2162 &occ->other_peer_identity, NULL, NULL, NULL,
2164 if (NULL == occ->p2th)
2166 occ->emsg = GNUNET_strdup ("Cannot connect to TRANSPORT of peer B");
2167 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2168 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2172 occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer");
2173 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
2178 * Function called after GNUNET_CORE_connect has succeeded (or failed
2179 * for good). Note that the private key of the peer is intentionally
2180 * not exposed here; if you need it, your process should try to read
2181 * the private key file directly (which should work if you are
2184 * @param cls closure
2185 * @param server handle to the server, NULL if we failed
2186 * @param my_identity ID of this peer, NULL if we failed
2189 core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
2190 const struct GNUNET_PeerIdentity *my_identity)
2192 struct OverlayConnectContext *occ = cls;
2194 GNUNET_free_non_null (occ->emsg);
2195 occ->emsg = GNUNET_strdup ("Failed to connect to CORE\n");
2196 if ((NULL == server) || (NULL == my_identity))
2198 GNUNET_free (occ->emsg);
2200 memcpy (&occ->peer_identity, my_identity,
2201 sizeof (struct GNUNET_PeerIdentity));
2203 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg,
2204 &occ->peer_identity, NULL, NULL, NULL, NULL);
2205 if (NULL == occ->p1th)
2207 GNUNET_asprintf (&occ->emsg, "Cannot connect to TRANSPORT of peers %4s",
2208 GNUNET_i2s (&occ->peer_identity));
2211 LOG_DEBUG ("Acquiring HELLO of peer %s\n", GNUNET_i2s (&occ->peer_identity));
2212 occ->emsg = GNUNET_strdup ("Timeout while acquiring HELLO message");
2213 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p1th, &hello_update_cb, occ);
2217 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2218 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2224 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
2227 * @param client identification of the client
2228 * @param message the actual message
2231 handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
2232 const struct GNUNET_MessageHeader *message)
2234 const struct GNUNET_TESTBED_OverlayConnectMessage *msg;
2235 struct OverlayConnectContext *occ;
2236 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2242 msg = (const struct GNUNET_TESTBED_OverlayConnectMessage *) message;
2243 p1 = ntohl (msg->peer1);
2244 p2 = ntohl (msg->peer2);
2245 GNUNET_assert (p1 < peer_list_size);
2246 GNUNET_assert (NULL != peer_list[p1]);
2247 GNUNET_assert (p2 < peer_list_size);
2248 GNUNET_assert (NULL != peer_list[p2]);
2249 /* FIXME: Add cases where we have to forward overlay connect message to sub
2251 GNUNET_assert (GNUNET_NO == peer_list[p1]->is_remote);
2252 occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
2253 GNUNET_SERVER_client_keep (client);
2254 occ->client = client;
2255 occ->peer = peer_list[p1];
2256 occ->other_peer = peer_list[p2];
2257 occ->op_id = GNUNET_ntohll (msg->operation_id);
2258 /* Get the identity of the second peer */
2259 GNUNET_TESTING_peer_get_identity (occ->other_peer->details.local.peer,
2260 &occ->other_peer_identity);
2261 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */
2262 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2264 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2265 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2266 GNUNET_NO, no_handlers);
2267 if (NULL == occ->ch)
2269 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2272 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2273 (GNUNET_TIME_UNIT_SECONDS, 30),
2274 &timeout_overlay_connect, occ);
2275 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2280 * Iterator over hash map entries.
2282 * @param cls closure
2283 * @param key current key code
2284 * @param value value in the hash map
2285 * @return GNUNET_YES if we should continue to
2290 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
2292 struct SharedService *ss = value;
2294 GNUNET_assert (GNUNET_YES ==
2295 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
2296 GNUNET_free (ss->name);
2303 * Task to clean up and shutdown nicely
2306 * @param tc the TaskContext from scheduler
2309 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2311 struct LCFContextQueue *lcfq;
2314 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
2315 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
2316 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
2318 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
2319 if (NULL != lcfq_head)
2321 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
2323 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
2324 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
2326 if (NULL != lcfq_head->lcf->rhandle)
2327 GNUNET_TESTBED_cancel_registration (lcfq_head->lcf->rhandle);
2329 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
2330 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
2332 GNUNET_free (lcfq->lcf->msg);
2333 GNUNET_free (lcfq->lcf);
2334 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
2337 /* Clear peer list */
2338 for (id = 0; id < peer_list_size; id++)
2339 if (NULL != peer_list[id])
2341 if (GNUNET_NO == peer_list[id]->is_remote)
2343 if (GNUNET_YES == peer_list[id]->details.local.is_running)
2344 GNUNET_TESTING_peer_stop (peer_list[id]->details.local.peer);
2345 GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
2346 GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
2348 GNUNET_free (peer_list[id]);
2350 GNUNET_free_non_null (peer_list);
2351 /* Clear host list */
2352 for (id = 0; id < host_list_size; id++)
2353 if (NULL != host_list[id])
2354 GNUNET_TESTBED_host_destroy (host_list[id]);
2355 GNUNET_free_non_null (host_list);
2356 /* Clear route list */
2357 for (id = 0; id < route_list_size; id++)
2358 if (NULL != route_list[id])
2359 GNUNET_free (route_list[id]);
2360 GNUNET_free_non_null (route_list);
2361 /* Clear slave_list */
2362 for (id = 0; id < slave_list_size; id++)
2363 if (NULL != slave_list[id])
2365 if (NULL != slave_list[id]->controller)
2366 GNUNET_TESTBED_controller_disconnect (slave_list[id]->controller);
2367 if (NULL != slave_list[id]->controller_proc)
2368 GNUNET_TESTBED_controller_stop (slave_list[id]->controller_proc);
2370 if (NULL != master_context)
2372 GNUNET_free_non_null (master_context->master_ip);
2373 if (NULL != master_context->system)
2374 GNUNET_TESTING_system_destroy (master_context->system, GNUNET_YES);
2375 GNUNET_free (master_context);
2376 master_context = NULL;
2382 * Callback for client disconnect
2385 * @param client the client which has disconnected
2388 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
2390 if (NULL == master_context)
2392 if (client == master_context->client)
2394 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
2395 GNUNET_SERVER_client_drop (client);
2396 /* should not be needed as we're terminated by failure to read
2397 * from stdin, but if stdin fails for some reason, this shouldn't
2398 * hurt for now --- might need to revise this later if we ever
2399 * decide that master connections might be temporarily down
2400 * for some reason */
2401 //GNUNET_SCHEDULER_shutdown ();
2409 * @param cls closure
2410 * @param server the initialized server
2411 * @param cfg configuration to use
2414 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
2415 const struct GNUNET_CONFIGURATION_Handle *cfg)
2417 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
2418 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
2419 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
2420 {&handle_configure_shared_service, NULL,
2421 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
2422 {&handle_link_controllers, NULL,
2423 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
2424 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
2425 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER,
2426 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
2427 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER,
2428 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
2429 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER,
2430 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
2431 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG,
2432 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
2433 {&handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT,
2434 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
2438 GNUNET_SERVER_add_handlers (server, message_handlers);
2439 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
2440 ss_map = GNUNET_CONTAINER_multihashmap_create (5);
2442 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2443 &shutdown_task, NULL);
2444 LOG_DEBUG ("Testbed startup complete\n");
2449 * The starting point of execution
2452 main (int argc, char *const *argv)
2454 //sleep (15); /* Debugging */
2455 return (GNUNET_OK ==
2456 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
2457 &testbed_run, NULL)) ? 0 : 1;
2460 /* end of gnunet-service-testbed.c */