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 * Our host id according to this context
91 * The message queue for sending messages to clients
96 * The message to be sent
98 struct GNUNET_MessageHeader *msg;
101 * The client to send the message to
103 struct GNUNET_SERVER_Client *client;
106 * next pointer for DLL
108 struct MessageQueue *next;
111 * prev pointer for DLL
113 struct MessageQueue *prev;
118 * The structure for identifying a shared service
123 * The name of the shared service
128 * Number of shared peers per instance of the shared service
133 * Number of peers currently sharing the service
135 uint32_t num_sharing;
150 * The destination host is reachable thru
157 * Context information used while linking controllers
159 struct LinkControllersContext;
163 * Structure representing a connected(directly-linked) controller
168 * The controller process handle if we had started the controller
170 struct GNUNET_TESTBED_ControllerProc *controller_proc;
173 * The controller handle
175 struct GNUNET_TESTBED_Controller *controller;
178 * The configuration of the slave. Cannot be NULL
180 struct GNUNET_CONFIGURATION_Handle *cfg;
183 * handle to lcc which is associated with this slave startup. Should be set to
184 * NULL when the slave has successfully started up
186 struct LinkControllersContext *lcc;
189 * The id of the host this controller is running on
196 * States of LCFContext
201 * The Context has been initialized; Nothing has been done on it
206 * Delegated host has been registered at the forwarding controller
208 DELEGATED_HOST_REGISTERED,
211 * The slave host has been registred at the forwarding controller
213 SLAVE_HOST_REGISTERED,
216 * The context has been finished (may have error)
223 * Link controllers request forwarding context
228 * The gateway which will pass the link message to delegated host
230 struct Slave *gateway;
233 * The controller link message that has to be forwarded to
235 struct GNUNET_TESTBED_ControllerLinkMessage *msg;
238 * The client which has asked to perform this operation
240 struct GNUNET_SERVER_Client *client;
243 * The host registration handle while registered hosts in this context
245 struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
248 * The id of the operation which created this context
250 uint64_t operation_id;
253 * The state of this context
255 enum LCFContextState state;
260 uint32_t delegated_host_id;
265 uint32_t slave_host_id;
271 * Structure of a queue entry in LCFContext request queue
273 struct LCFContextQueue
278 struct LCFContext *lcf;
283 struct LCFContextQueue *next;
288 struct LCFContextQueue *prev;
302 * The peer handle from testing API
304 struct GNUNET_TESTING_Peer *peer;
307 * The modified (by GNUNET_TESTING_peer_configure) configuration this
308 * peer is configured with
310 struct GNUNET_CONFIGURATION_Handle *cfg;
313 * Is the peer running
322 * The controller this peer is started through
324 struct GNUNET_TESTBED_Controller *controller;
327 * The id of the remote host this peer is running on
329 uint32_t remote_host_id;
336 * Is this peer locally created?
341 * Our local reference id for this peer
349 * Context information for connecting 2 peers in overlay
351 struct OverlayConnectContext
354 * The client which has requested for overlay connection
356 struct GNUNET_SERVER_Client *client;
359 * the peer which has to connect to the other peer
364 * Transport handle of the first peer to get its HELLO
366 struct GNUNET_TRANSPORT_Handle *p1th;
369 * Transport handle of other peer to offer first peer's HELLO
371 struct GNUNET_TRANSPORT_Handle *p2th;
374 * Core handles of the first peer; used to notify when second peer connects to it
376 struct GNUNET_CORE_Handle *ch;
379 * HELLO of the other peer
381 struct GNUNET_MessageHeader *hello;
384 * Get hello handle to acquire HELLO of first peer
386 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
389 * The error message we send if this overlay connect operation has timed out
394 * Operation context for suboperations
396 struct OperationContext *opc;
399 * Controller of peer 2; NULL if the peer is local
401 struct GNUNET_TESTBED_Controller *peer2_controller;
404 * The peer identity of the first peer
406 struct GNUNET_PeerIdentity peer_identity;
409 * The peer identity of the other peer
411 struct GNUNET_PeerIdentity other_peer_identity;
414 * The id of the operation responsible for creating this context
419 * The id of the task for sending HELLO of peer 2 to peer 1 and ask peer 1 to
422 GNUNET_SCHEDULER_TaskIdentifier send_hello_task;
425 * The id of the overlay connect timeout task
427 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
437 uint32_t other_peer_id;
440 * Number of times we tried to send hello; used to increase delay in offering
448 * Context information for RequestOverlayConnect
449 * operations. RequestOverlayConnect is used when peers A, B reside on different
450 * hosts and the host controller for peer B is asked by the host controller of
451 * peer A to make peer B connect to peer A
453 struct RequestOverlayConnectContext
456 * The transport handle of peer B
458 struct GNUNET_TRANSPORT_Handle *th;
463 struct GNUNET_MessageHeader *hello;
466 * The peer identity of peer A
468 struct GNUNET_PeerIdentity a_id;
471 * Task for offering HELLO of A to B and doing try_connect
473 GNUNET_SCHEDULER_TaskIdentifier attempt_connect_task_id;
476 * Task to timeout RequestOverlayConnect
478 GNUNET_SCHEDULER_TaskIdentifier timeout_rocc_task_id;
481 * Number of times we tried to send hello; used to increase delay in offering
490 * Context information for operations forwarded to subcontrollers
492 struct ForwardedOperationContext
495 * The generated operation context
497 struct OperationContext *opc;
500 * The client to which we have to reply
502 struct GNUNET_SERVER_Client *client;
510 * Task ID for the timeout task
512 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
515 * The id of the operation that has been forwarded
517 uint64_t operation_id;
523 * Context information used while linking controllers
525 struct LinkControllersContext
528 * The client which initiated the link controller operation
530 struct GNUNET_SERVER_Client *client;
533 * The ID of the operation
535 uint64_t operation_id;
541 * Context information to used during operations which forward the overlay
544 struct ForwardedOverlayConnectContext
547 * The gateway controller to which this operation is forwarded to
549 struct GNUNET_TESTBED_Controller *gateway;
552 * The gateway controller through which peer2's controller can be reached
554 struct GNUNET_TESTBED_Controller *gateway2;
557 * Handle for sub-operations
559 struct GNUNET_TESTBED_Operation *sub_op;
562 * The client which initiated the link controller operation
564 struct GNUNET_SERVER_Client *client;
567 * A copy of the original overlay connect message
569 struct GNUNET_MessageHeader *orig_msg;
572 * The host registration handle while registered hosts in this context
574 struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
577 * The id of the operation which created this context information
579 uint64_t operation_id;
582 * Enumeration of states for this context
592 * State where we attempt to register peer2's controller with peer1's controller
597 * State where we attempt to get peer2's controller configuration
602 * State where we attempt to link the controller of peer 1 to the controller
608 * State where we attempt to do the overlay connection again
625 * Id of the host where peer2 is running
627 uint32_t peer2_host_id;
633 * The master context; generated with the first INIT message
635 static struct Context *master_context;
638 * Our hostname; we give this to all the peers we start
640 static char *hostname;
650 static struct GNUNET_CONFIGURATION_Handle *our_config;
653 * Current Transmit Handle; NULL if no notify transmit exists currently
655 static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
662 * The head for the LCF queue
664 static struct LCFContextQueue *lcfq_head;
667 * The tail for the LCF queue
669 static struct LCFContextQueue *lcfq_tail;
672 * The message queue head
674 static struct MessageQueue *mq_head;
677 * The message queue tail
679 static struct MessageQueue *mq_tail;
684 static struct GNUNET_TESTBED_Host **host_list;
689 static struct Route **route_list;
692 * A list of directly linked neighbours
694 static struct Slave **slave_list;
697 * A list of peers we know about
699 static struct Peer **peer_list;
702 * The hashmap of shared services
704 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
707 * The event mask for the events we listen from sub-controllers
709 static uint64_t event_mask;
712 * The size of the host list
714 static uint32_t host_list_size;
717 * The size of the route list
719 static uint32_t route_list_size;
722 * The size of directly linked neighbours list
724 static uint32_t slave_list_size;
727 * The size of the peer list
729 static uint32_t peer_list_size;
736 * The lcf_task handle
738 static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
741 * The shutdown task handle
743 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
747 * Function called to notify a client about the connection begin ready to queue
748 * more data. "buf" will be NULL and "size" zero if the connection was closed
749 * for writing in the meantime.
752 * @param size number of bytes available in buf
753 * @param buf where the callee should write the message
754 * @return number of bytes written to buf
757 transmit_ready_notify (void *cls, size_t size, void *buf)
759 struct MessageQueue *mq_entry;
761 transmit_handle = NULL;
763 GNUNET_assert (NULL != mq_entry);
766 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
767 size = ntohs (mq_entry->msg->size);
768 memcpy (buf, mq_entry->msg, size);
769 GNUNET_free (mq_entry->msg);
770 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
771 GNUNET_free (mq_entry);
773 if (NULL != mq_entry)
775 GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
776 ntohs (mq_entry->msg->size),
777 GNUNET_TIME_UNIT_FOREVER_REL,
778 &transmit_ready_notify, NULL);
784 * Queues a message in send queue for sending to the service
786 * @param client the client to whom the queued message has to be sent
787 * @param msg the message to queue
790 queue_message (struct GNUNET_SERVER_Client *client,
791 struct GNUNET_MessageHeader *msg)
793 struct MessageQueue *mq_entry;
797 type = ntohs (msg->type);
798 size = ntohs (msg->size);
799 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
800 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
801 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
803 mq_entry->client = client;
804 LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type,
806 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
807 if (NULL == transmit_handle)
809 GNUNET_SERVER_notify_transmit_ready (client, size,
810 GNUNET_TIME_UNIT_FOREVER_REL,
811 &transmit_ready_notify, NULL);
816 * Similar to GNUNET_realloc; however clears tail part of newly allocated memory
818 * @param ptr the memory block to realloc
819 * @param size the size of ptr
820 * @param new_size the size to which ptr has to be realloc'ed
821 * @return the newly reallocated memory block
824 TESTBED_realloc (void *ptr, size_t size, size_t new_size)
826 ptr = GNUNET_realloc (ptr, new_size);
828 (void) memset (ptr + size, 0, new_size - size);
834 * Function to add a host to the current list of known hosts
836 * @param host the host to add
837 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
841 host_list_add (struct GNUNET_TESTBED_Host *host)
846 host_id = GNUNET_TESTBED_host_get_id_ (host);
847 orig_size = host_list_size;
848 if (host_list_size <= host_id)
850 while (host_list_size <= host_id)
851 host_list_size += LIST_GROW_STEP;
853 TESTBED_realloc (host_list,
854 sizeof (struct GNUNET_TESTBED_Host *) * orig_size,
855 sizeof (struct GNUNET_TESTBED_Host *)
858 if (NULL != host_list[host_id])
860 LOG_DEBUG ("A host with id: %u already exists\n", host_id);
861 return GNUNET_SYSERR;
863 host_list[host_id] = host;
869 * Adds a route to the route list
871 * @param route the route to add
874 route_list_add (struct Route *route)
878 orig_size = route_list_size;
879 if (route->dest >= route_list_size)
881 while (route->dest >= route_list_size)
882 route_list_size += LIST_GROW_STEP;
884 TESTBED_realloc (route_list,
885 sizeof (struct Route *) * orig_size,
886 sizeof (struct Route *) * route_list_size);
888 GNUNET_assert (NULL == route_list[route->dest]);
889 route_list[route->dest] = route;
894 * Adds a slave to the slave array
896 * @param slave the slave controller to add
899 slave_list_add (struct Slave *slave)
901 if (slave->host_id >= slave_list_size)
904 TESTBED_realloc (slave_list, sizeof (struct Slave *) * slave_list_size,
905 sizeof (struct Slave *) * (slave_list_size +
907 slave_list_size += LIST_GROW_STEP;
909 GNUNET_assert (NULL == slave_list[slave->host_id]);
910 slave_list[slave->host_id] = slave;
915 * Adds a peer to the peer array
917 * @param peer the peer to add
920 peer_list_add (struct Peer *peer)
924 orig_size = peer_list_size;
925 if (peer->id >= peer_list_size)
927 while (peer->id >= peer_list_size)
928 peer_list_size += LIST_GROW_STEP;
930 TESTBED_realloc (peer_list, sizeof (struct Peer *) * orig_size,
931 sizeof (struct Peer *) * peer_list_size);
933 GNUNET_assert (NULL == peer_list[peer->id]);
934 peer_list[peer->id] = peer;
939 * Removes a the give peer from the peer array
941 * @param peer the peer to be removed
944 peer_list_remove (struct Peer *peer)
949 peer_list[peer->id] = NULL;
950 orig_size = peer_list_size;
951 while (peer_list_size >= LIST_GROW_STEP)
953 for (id = peer_list_size - 1;
954 (id >= peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); id--)
955 if (NULL != peer_list[id])
957 if (id != ((peer_list_size - LIST_GROW_STEP) - 1))
959 peer_list_size -= LIST_GROW_STEP;
961 if (orig_size == peer_list_size)
964 GNUNET_realloc (peer_list, sizeof (struct Peer *) * peer_list_size);
969 * Finds the route with directly connected host as destination through which
970 * the destination host can be reached
972 * @param host_id the id of the destination host
973 * @return the route with directly connected destination host; NULL if no route
976 static struct Route *
977 find_dest_route (uint32_t host_id)
981 if (route_list_size <= host_id)
983 while (NULL != (route = route_list[host_id]))
985 if (route->thru == master_context->host_id)
987 host_id = route->thru;
994 * Routes message to a host given its host_id
996 * @param host_id the id of the destination host
997 * @param msg the message to be routed
1000 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
1007 * Send operation failure message to client
1009 * @param client the client to which the failure message has to be sent to
1010 * @param operation_id the id of the failed operation
1011 * @param emsg the error message; can be NULL
1014 send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
1015 uint64_t operation_id, const char *emsg)
1017 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
1021 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
1022 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
1024 msg = GNUNET_malloc (msize);
1025 msg->header.size = htons (msize);
1026 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONFAILEVENT);
1027 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
1028 msg->operation_id = GNUNET_htonll (operation_id);
1030 memcpy (&msg[1], emsg, emsg_len);
1031 queue_message (client, &msg->header);
1036 * Function to send generic operation success message to given client
1038 * @param client the client to send the message to
1039 * @param operation_id the id of the operation which was successful
1042 send_operation_success_msg (struct GNUNET_SERVER_Client *client,
1043 uint64_t operation_id)
1045 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
1048 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
1049 msg = GNUNET_malloc (msize);
1050 msg->header.size = htons (msize);
1051 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
1052 msg->operation_id = GNUNET_htonll (operation_id);
1053 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
1054 queue_message (client, &msg->header);
1059 * The Link Controller forwarding task
1061 * @param cls the LCFContext
1062 * @param tc the Task context from scheduler
1065 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1069 * Completion callback for host registrations while forwarding Link Controller messages
1071 * @param cls the LCFContext
1072 * @param emsg the error message; NULL if host registration is successful
1075 lcf_proc_cc (void *cls, const char *emsg)
1077 struct LCFContext *lcf = cls;
1079 lcf->rhandle = NULL;
1080 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1085 goto registration_error;
1086 lcf->state = DELEGATED_HOST_REGISTERED;
1087 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1089 case DELEGATED_HOST_REGISTERED:
1091 goto registration_error;
1092 lcf->state = SLAVE_HOST_REGISTERED;
1093 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1096 GNUNET_assert (0); /* Shouldn't reach here */
1101 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
1103 lcf->state = FINISHED;
1104 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1109 * Callback to be called when forwarded link controllers operation is
1110 * successfull. We have to relay the reply msg back to the client
1112 * @param cls ForwardedOperationContext
1113 * @param msg the peer create success message
1116 forwarded_operation_reply_relay (void *cls,
1117 const struct GNUNET_MessageHeader *msg)
1119 struct ForwardedOperationContext *fopc = cls;
1120 struct GNUNET_MessageHeader *dup_msg;
1123 msize = ntohs (msg->size);
1124 LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type),
1126 dup_msg = GNUNET_malloc (msize);
1127 (void) memcpy (dup_msg, msg, msize);
1128 queue_message (fopc->client, dup_msg);
1129 GNUNET_SERVER_client_drop (fopc->client);
1130 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
1136 * Task to free resources when forwarded link controllers has been timedout
1138 * @param cls the ForwardedOperationContext
1139 * @param tc the task context from scheduler
1142 forwarded_operation_timeout (void *cls,
1143 const struct GNUNET_SCHEDULER_TaskContext *tc)
1145 struct ForwardedOperationContext *fopc = cls;
1147 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
1148 send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
1149 GNUNET_SERVER_client_drop (fopc->client);
1155 * The Link Controller forwarding task
1157 * @param cls the LCFContext
1158 * @param tc the Task context from scheduler
1161 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1163 struct LCFContext *lcf = cls;
1164 struct LCFContextQueue *lcfq;
1165 struct ForwardedOperationContext *fopc;
1167 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
1172 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id],
1173 lcf->gateway->controller))
1176 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1177 host_list[lcf->delegated_host_id],
1182 lcf->state = DELEGATED_HOST_REGISTERED;
1183 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1186 case DELEGATED_HOST_REGISTERED:
1188 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id],
1189 lcf->gateway->controller))
1192 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1193 host_list[lcf->slave_host_id],
1198 lcf->state = SLAVE_HOST_REGISTERED;
1199 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1202 case SLAVE_HOST_REGISTERED:
1203 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1204 fopc->client = lcf->client;
1205 fopc->operation_id = lcf->operation_id;
1207 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
1210 &forwarded_operation_reply_relay,
1212 fopc->timeout_task =
1213 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1215 lcf->state = FINISHED;
1216 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1220 GNUNET_assert (lcfq->lcf == lcf);
1221 GNUNET_free (lcf->msg);
1223 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
1225 if (NULL != lcfq_head)
1227 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
1233 * Callback to be called when forwarded overlay connection operation has a reply
1234 * from the sub-controller successfull. We have to relay the reply msg back to
1237 * @param cls ForwardedOperationContext
1238 * @param msg the peer create success message
1241 forwarded_overlay_connect_listener (void *cls,
1242 const struct GNUNET_MessageHeader *msg);
1246 * Cleans up ForwardedOverlayConnectContext
1248 * @param focc the ForwardedOverlayConnectContext to cleanup
1251 cleanup_focc (struct ForwardedOverlayConnectContext *focc)
1253 if (NULL != focc->sub_op)
1254 GNUNET_TESTBED_operation_done (focc->sub_op);
1255 if (NULL != focc->client)
1256 GNUNET_SERVER_client_drop (focc->client);
1257 GNUNET_free_non_null (focc->orig_msg);
1262 * Callback for event from slave controllers
1264 * @param cls struct Slave *
1265 * @param event information about the event
1268 slave_event_callback (void *cls,
1269 const struct GNUNET_TESTBED_EventInformation *event)
1271 struct ForwardedOverlayConnectContext *focc;
1272 struct ForwardedOperationContext *fopc;
1273 struct GNUNET_CONFIGURATION_Handle *slave_cfg;
1274 struct GNUNET_TESTBED_Operation *old_op;
1277 /* We currently only get here when doing overlay connect operations and that
1278 too while trying out sub operations */
1279 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
1280 focc = event->details.operation_finished.op_cls;
1281 LOG_DEBUG ("Operation successful\n");
1282 if (NULL != event->details.operation_finished.emsg)
1284 GNUNET_asprintf (&emsg, "Failure executing suboperation: %s",
1285 event->details.operation_finished.emsg);
1286 send_operation_fail_msg (focc->client, focc->operation_id,
1289 cleanup_focc (focc);
1292 switch (focc->state)
1295 slave_cfg = event->details.operation_finished.generic;
1296 old_op = focc->sub_op;
1297 focc->state = FOCC_LINK;
1298 focc->sub_op = GNUNET_TESTBED_controller_link_ (focc,
1300 focc->peer2_host_id,
1301 peer_list[focc->peer1]->details.remote.remote_host_id,
1304 GNUNET_TESTBED_operation_done (old_op);
1307 LOG_DEBUG ("OL: Linking controllers successfull\n");
1308 GNUNET_TESTBED_operation_done (focc->sub_op);
1309 focc->sub_op = NULL;
1310 focc->state = FOCC_OL_CONNECT;
1311 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1312 fopc->client = focc->client;
1313 focc->client = NULL;
1314 fopc->operation_id = focc->operation_id;
1317 GNUNET_TESTBED_forward_operation_msg_ (focc->gateway,
1318 focc->operation_id, focc->orig_msg,
1319 &forwarded_operation_reply_relay,
1321 GNUNET_free (focc->orig_msg);
1322 focc->orig_msg = NULL;
1323 fopc->timeout_task =
1324 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1326 cleanup_focc (focc);
1336 * Callback to signal successfull startup of the controller process
1338 * @param cls the handle to the slave whose status is to be found here
1339 * @param cfg the configuration with which the controller has been started;
1340 * NULL if status is not GNUNET_OK
1341 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
1342 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1345 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
1348 struct Slave *slave = cls;
1349 struct LinkControllersContext *lcc;
1352 if (GNUNET_SYSERR == status)
1354 slave->controller_proc = NULL;
1355 slave_list[slave->host_id] = NULL;
1356 if (NULL != slave->cfg)
1357 GNUNET_CONFIGURATION_destroy (slave->cfg);
1358 GNUNET_free (slave);
1360 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
1361 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
1365 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1367 &slave_event_callback, slave);
1368 if (NULL != slave->controller)
1370 send_operation_success_msg (lcc->client, lcc->operation_id);
1371 slave->cfg = GNUNET_CONFIGURATION_dup (cfg);
1375 send_operation_fail_msg (lcc->client, lcc->operation_id,
1376 "Could not connect to delegated controller");
1377 GNUNET_TESTBED_controller_stop (slave->controller_proc);
1378 slave_list[slave->host_id] = NULL;
1379 GNUNET_free (slave);
1386 if (NULL != lcc->client)
1388 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
1389 GNUNET_SERVER_client_drop (lcc->client);
1400 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
1403 * @param client identification of the client
1404 * @param message the actual message
1407 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
1408 const struct GNUNET_MessageHeader *message)
1410 const struct GNUNET_TESTBED_InitMessage *msg;
1411 struct GNUNET_TESTBED_Host *host;
1412 const char *controller_hostname;
1415 if (NULL != master_context)
1417 LOG_DEBUG ("We are being connected to laterally\n");
1418 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1421 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
1422 msize = ntohs (message->size);
1423 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
1426 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1429 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
1430 controller_hostname = (const char *) &msg[1];
1431 if ('\0' != controller_hostname[msize - 1])
1434 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1437 master_context = GNUNET_malloc (sizeof (struct Context));
1438 master_context->client = client;
1439 master_context->host_id = ntohl (msg->host_id);
1440 master_context->master_ip = GNUNET_strdup (controller_hostname);
1441 LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip);
1442 master_context->system =
1443 GNUNET_TESTING_system_create ("testbed", master_context->master_ip, hostname);
1445 GNUNET_TESTBED_host_create_with_id (master_context->host_id,
1446 master_context->master_ip,
1449 host_list_add (host);
1450 GNUNET_SERVER_client_keep (client);
1451 LOG_DEBUG ("Created master context with host ID: %u\n",
1452 master_context->host_id);
1453 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1458 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1461 * @param client identification of the client
1462 * @param message the actual message
1465 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
1466 const struct GNUNET_MessageHeader *message)
1468 struct GNUNET_TESTBED_Host *host;
1469 const struct GNUNET_TESTBED_AddHostMessage *msg;
1470 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
1475 uint16_t username_length;
1476 uint16_t hostname_length;
1477 uint16_t reply_size;
1480 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
1481 msize = ntohs (msg->header.size);
1482 username = (char *) &(msg[1]);
1483 username_length = ntohs (msg->user_name_length);
1484 GNUNET_assert (msize > (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length + 1)); /* msg must contain hostname */
1485 if (0 != username_length)
1486 GNUNET_assert ('\0' == username[username_length]);
1487 username_length = (0 == username_length) ? 0 : username_length + 1;
1488 hostname = username + username_length;
1490 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
1491 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
1492 GNUNET_assert (strlen (hostname) == hostname_length - 1);
1493 host_id = ntohl (msg->host_id);
1494 LOG_DEBUG ("Received ADDHOST message\n");
1495 LOG_DEBUG ("-------host id: %u\n", host_id);
1496 LOG_DEBUG ("-------hostname: %s\n", hostname);
1497 if (0 != username_length)
1498 LOG_DEBUG ("-------username: %s\n", username);
1501 LOG_DEBUG ("-------username: NULL\n");
1504 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1506 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1507 ntohs (msg->ssh_port));
1508 GNUNET_assert (NULL != host);
1509 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1510 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1511 if (GNUNET_OK != host_list_add (host))
1513 /* We are unable to add a host */
1514 emsg = "A host exists with given host-id";
1515 LOG_DEBUG ("%s: %u", emsg, host_id);
1516 GNUNET_TESTBED_host_destroy (host);
1517 reply_size += strlen (emsg) + 1;
1518 reply = GNUNET_malloc (reply_size);
1519 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1522 reply = GNUNET_malloc (reply_size);
1523 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
1524 reply->header.size = htons (reply_size);
1525 reply->host_id = htonl (host_id);
1526 queue_message (client, &reply->header);
1531 * Iterator over hash map entries.
1533 * @param cls closure
1534 * @param key current key code
1535 * @param value value in the hash map
1536 * @return GNUNET_YES if we should continue to
1541 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1543 struct SharedService *queried_ss = cls;
1544 struct SharedService *ss = value;
1546 if (0 == strcmp (ss->name, queried_ss->name))
1554 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1557 * @param client identification of the client
1558 * @param message the actual message
1561 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1562 const struct GNUNET_MessageHeader *message)
1564 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1565 struct SharedService *ss;
1567 struct GNUNET_HashCode hash;
1569 uint16_t service_name_size;
1571 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1572 msg_size = ntohs (message->size);
1573 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1576 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1580 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1581 service_name = (char *) &msg[1];
1582 if ('\0' != service_name[service_name_size - 1])
1585 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1588 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1589 service_name, ntohl (msg->num_peers));
1590 if (ntohl (msg->host_id) != master_context->host_id)
1592 route_message (ntohl (msg->host_id), message);
1593 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1596 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1597 ss = GNUNET_malloc (sizeof (struct SharedService));
1598 ss->name = strdup (service_name);
1599 ss->num_shared = ntohl (msg->num_peers);
1600 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1601 if (GNUNET_SYSERR ==
1602 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1603 &ss_exists_iterator, ss))
1605 LOG (GNUNET_ERROR_TYPE_WARNING,
1606 "Service %s already configured as a shared service. "
1607 "Ignoring service sharing request \n", ss->name);
1608 GNUNET_free (ss->name);
1612 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1613 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1618 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1621 * @param client identification of the client
1622 * @param message the actual message
1625 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1626 const struct GNUNET_MessageHeader *message)
1628 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1629 struct GNUNET_CONFIGURATION_Handle *cfg;
1630 struct LCFContextQueue *lcfq;
1631 struct Route *route;
1632 struct Route *new_route;
1636 uint32_t delegated_host_id;
1637 uint32_t slave_host_id;
1640 if (NULL == master_context)
1643 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1646 msize = ntohs (message->size);
1647 if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
1650 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1653 msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
1654 delegated_host_id = ntohl (msg->delegated_host_id);
1655 if (delegated_host_id == master_context->host_id)
1658 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1659 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1662 if ((delegated_host_id >= host_list_size) ||
1663 (NULL == host_list[delegated_host_id]))
1665 LOG (GNUNET_ERROR_TYPE_WARNING,
1666 "Delegated host %u not registered with us\n", delegated_host_id);
1667 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1670 slave_host_id = ntohl (msg->slave_host_id);
1671 if ((slave_host_id >= host_list_size) || (NULL == host_list[slave_host_id]))
1673 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host not registered with us\n");
1674 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1677 if (slave_host_id == delegated_host_id)
1679 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1680 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1684 if (slave_host_id == master_context->host_id) /* Link from us */
1686 struct Slave *slave;
1687 struct LinkControllersContext *lcc;
1689 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1690 config_size = ntohs (msg->config_size);
1691 if ((delegated_host_id < slave_list_size) && (NULL != slave_list[delegated_host_id])) /* We have already added */
1693 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1695 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1698 config = GNUNET_malloc (config_size);
1699 dest_size = (uLongf) config_size;
1701 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1704 GNUNET_break (0); /* Compression error */
1705 GNUNET_free (config);
1706 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1709 if (config_size != dest_size)
1711 LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1712 GNUNET_free (config);
1713 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1716 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1718 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1720 GNUNET_break (0); /* Configuration parsing error */
1721 GNUNET_free (config);
1722 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1725 GNUNET_free (config);
1726 if ((delegated_host_id < slave_list_size) &&
1727 (NULL != slave_list[delegated_host_id]))
1729 GNUNET_break (0); /* Configuration parsing error */
1730 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1733 slave = GNUNET_malloc (sizeof (struct Slave));
1734 slave->host_id = delegated_host_id;
1735 slave_list_add (slave);
1736 if (1 != msg->is_subordinate)
1739 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1741 &slave_event_callback, slave);
1743 if (NULL != slave->controller)
1744 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1746 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1747 "Could not connect to delegated controller");
1748 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1751 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1752 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1753 GNUNET_SERVER_client_keep (client);
1754 lcc->client = client;
1756 slave->controller_proc =
1757 GNUNET_TESTBED_controller_start (master_context->master_ip,
1758 host_list[slave->host_id], cfg,
1759 &slave_status_callback, slave);
1760 GNUNET_CONFIGURATION_destroy (cfg);
1761 new_route = GNUNET_malloc (sizeof (struct Route));
1762 new_route->dest = delegated_host_id;
1763 new_route->thru = master_context->host_id;
1764 route_list_add (new_route);
1768 /* Route the request */
1769 if (slave_host_id >= route_list_size)
1771 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1772 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1775 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1776 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1777 lcfq->lcf->delegated_host_id = delegated_host_id;
1778 lcfq->lcf->slave_host_id = slave_host_id;
1779 route = find_dest_route (slave_host_id);
1780 GNUNET_assert (NULL != route); /* because we add routes carefully */
1781 GNUNET_assert (route->dest < slave_list_size);
1782 GNUNET_assert (NULL != slave_list[route->dest]);
1783 lcfq->lcf->state = INIT;
1784 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1785 lcfq->lcf->gateway = slave_list[route->dest];
1786 lcfq->lcf->msg = GNUNET_malloc (msize);
1787 (void) memcpy (lcfq->lcf->msg, msg, msize);
1788 GNUNET_SERVER_client_keep (client);
1789 lcfq->lcf->client = client;
1790 if (NULL == lcfq_head)
1792 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1793 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1794 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1797 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1798 /* FIXME: Adding a new route should happen after the controllers are linked
1800 if (1 != msg->is_subordinate)
1802 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1805 if ((delegated_host_id < route_list_size)
1806 && (NULL != route_list[delegated_host_id]))
1808 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1809 with is subordinate flag set to GNUNET_YES? */
1810 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1813 new_route = GNUNET_malloc (sizeof (struct Route));
1814 new_route->dest = delegated_host_id;
1815 new_route->thru = route->dest;
1816 route_list_add (new_route);
1817 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1822 * The task to be executed if the forwarded peer create operation has been
1825 * @param cls the FowardedOperationContext
1826 * @param tc the TaskContext from the scheduler
1829 peer_create_forward_timeout (void *cls,
1830 const struct GNUNET_SCHEDULER_TaskContext *tc)
1832 struct ForwardedOperationContext *fo_ctxt = cls;
1834 /* send error msg to client */
1835 GNUNET_free (fo_ctxt->cls);
1836 send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, "Timedout");
1837 GNUNET_SERVER_client_drop (fo_ctxt->client);
1838 GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc);
1839 GNUNET_free (fo_ctxt);
1844 * Callback to be called when forwarded peer create operation is
1845 * successfull. We have to relay the reply msg back to the client
1847 * @param cls ForwardedOperationContext
1848 * @param msg the peer create success message
1851 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1853 struct ForwardedOperationContext *fo_ctxt = cls;
1854 const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *success_msg;
1855 struct GNUNET_MessageHeader *dup_msg;
1856 struct Peer *remote_peer;
1859 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);
1860 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
1863 (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *) msg;
1864 GNUNET_assert (NULL != fo_ctxt->cls);
1865 remote_peer = fo_ctxt->cls;
1866 GNUNET_assert (remote_peer->details.remote.remote_host_id
1867 == ntohl (success_msg->peer_id));
1868 peer_list_add (remote_peer);
1870 msize = ntohs (msg->size);
1871 dup_msg = GNUNET_malloc (msize);
1872 (void) memcpy (dup_msg, msg, msize);
1873 queue_message (fo_ctxt->client, dup_msg);
1874 GNUNET_SERVER_client_drop (fo_ctxt->client);
1875 GNUNET_free (fo_ctxt);
1881 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1884 * @param client identification of the client
1885 * @param message the actual message
1888 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1889 const struct GNUNET_MessageHeader *message)
1891 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1892 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1893 struct GNUNET_CONFIGURATION_Handle *cfg;
1894 struct ForwardedOperationContext *fo_ctxt;
1895 struct Route *route;
1900 uint32_t config_size;
1906 msize = ntohs (message->size);
1907 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1909 GNUNET_break (0); /* We need configuration */
1910 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1913 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1914 host_id = ntohl (msg->host_id);
1915 peer_id = ntohl (msg->peer_id);
1916 if (UINT32_MAX == peer_id)
1918 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1919 "Cannot create peer with given ID");
1920 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1923 if (host_id == master_context->host_id)
1927 /* We are responsible for this peer */
1928 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1929 config_size = ntohl (msg->config_size);
1930 config = GNUNET_malloc (config_size);
1931 dest_size = config_size;
1934 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1935 (const Bytef *) &msg[1], (uLong) msize)))
1937 GNUNET_break (0); /* uncompression error */
1938 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1941 if (config_size != dest_size)
1943 GNUNET_break (0); /* Uncompressed config size mismatch */
1944 GNUNET_free (config);
1945 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1948 cfg = GNUNET_CONFIGURATION_create ();
1950 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1952 GNUNET_break (0); /* Configuration parsing error */
1953 GNUNET_free (config);
1954 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1957 GNUNET_free (config);
1958 peer = GNUNET_malloc (sizeof (struct Peer));
1959 peer->is_remote = GNUNET_NO;
1960 peer->details.local.cfg = cfg;
1962 LOG_DEBUG ("Creating peer with id: %u\n", peer->id);
1963 peer->details.local.peer =
1964 GNUNET_TESTING_peer_configure (master_context->system,
1965 peer->details.local.cfg, peer->id,
1966 NULL /* Peer id */ ,
1968 if (NULL == peer->details.local.peer)
1970 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1974 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1977 peer->details.local.is_running = GNUNET_NO;
1978 peer_list_add (peer);
1980 GNUNET_malloc (sizeof
1981 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1982 reply->header.size =
1983 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1984 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
1985 reply->peer_id = msg->peer_id;
1986 reply->operation_id = msg->operation_id;
1987 queue_message (client, &reply->header);
1988 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1992 /* Forward peer create request */
1993 route = find_dest_route (host_id);
1997 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2001 peer = GNUNET_malloc (sizeof (struct Peer));
2002 peer->is_remote = GNUNET_YES;
2004 peer->details.remote.controller = slave_list[route->dest]->controller;
2005 peer->details.remote.remote_host_id = host_id;
2006 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2007 GNUNET_SERVER_client_keep (client);
2008 fo_ctxt->client = client;
2009 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
2010 fo_ctxt->cls = peer; //slave_list[route->dest]->controller;
2012 GNUNET_TESTBED_forward_operation_msg_ (slave_list [route->dest]->controller,
2013 fo_ctxt->operation_id,
2015 peer_create_success_cb, fo_ctxt);
2016 fo_ctxt->timeout_task =
2017 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
2019 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2024 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2027 * @param client identification of the client
2028 * @param message the actual message
2031 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
2032 const struct GNUNET_MessageHeader *message)
2034 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
2035 struct ForwardedOperationContext *fopc;
2039 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
2040 peer_id = ntohl (msg->peer_id);
2041 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
2042 peer_id, GNUNET_ntohll (msg->operation_id));
2043 if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id]))
2045 LOG (GNUNET_ERROR_TYPE_ERROR,
2046 "Asked to destroy a non existent peer with id: %u\n", peer_id);
2047 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2048 "Peer doesn't exist");
2049 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2052 peer = peer_list[peer_id];
2053 if (GNUNET_YES == peer->is_remote)
2055 /* Forward the destory message to sub controller */
2056 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2057 GNUNET_SERVER_client_keep (client);
2058 fopc->client = client;
2059 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2061 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2062 fopc->operation_id, &msg->header,
2063 &forwarded_operation_reply_relay,
2065 fopc->timeout_task =
2066 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2068 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2071 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
2072 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
2073 peer_list_remove (peer);
2075 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
2076 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2081 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2084 * @param client identification of the client
2085 * @param message the actual message
2088 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
2089 const struct GNUNET_MessageHeader *message)
2091 const struct GNUNET_TESTBED_PeerStartMessage *msg;
2092 struct GNUNET_TESTBED_PeerEventMessage *reply;
2093 struct ForwardedOperationContext *fopc;
2097 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
2098 peer_id = ntohl (msg->peer_id);
2099 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2102 LOG (GNUNET_ERROR_TYPE_ERROR,
2103 "Asked to start a non existent peer with id: %u\n", peer_id);
2104 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2107 peer = peer_list[peer_id];
2108 if (GNUNET_YES == peer->is_remote)
2110 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2111 GNUNET_SERVER_client_keep (client);
2112 fopc->client = client;
2113 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2115 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2116 fopc->operation_id, &msg->header,
2117 &forwarded_operation_reply_relay,
2119 fopc->timeout_task =
2120 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2122 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2125 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
2127 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2129 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2132 peer->details.local.is_running = GNUNET_YES;
2133 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2134 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
2135 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2136 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
2137 reply->host_id = htonl (master_context->host_id);
2138 reply->peer_id = msg->peer_id;
2139 reply->operation_id = msg->operation_id;
2140 queue_message (client, &reply->header);
2141 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2146 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2149 * @param client identification of the client
2150 * @param message the actual message
2153 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
2154 const struct GNUNET_MessageHeader *message)
2156 const struct GNUNET_TESTBED_PeerStopMessage *msg;
2157 struct GNUNET_TESTBED_PeerEventMessage *reply;
2158 struct ForwardedOperationContext *fopc;
2162 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
2163 peer_id = ntohl (msg->peer_id);
2164 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2166 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2168 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2171 peer = peer_list[peer_id];
2172 if (GNUNET_YES == peer->is_remote)
2174 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2175 GNUNET_SERVER_client_keep (client);
2176 fopc->client = client;
2177 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2179 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2180 fopc->operation_id, &msg->header,
2181 &forwarded_operation_reply_relay,
2183 fopc->timeout_task =
2184 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2186 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2189 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer->details.local.peer))
2191 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2192 "Peer not running");
2193 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2196 peer->details.local.is_running = GNUNET_NO;
2197 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2198 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
2199 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2200 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
2201 reply->host_id = htonl (master_context->host_id);
2202 reply->peer_id = msg->peer_id;
2203 reply->operation_id = msg->operation_id;
2204 queue_message (client, &reply->header);
2205 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2210 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
2213 * @param client identification of the client
2214 * @param message the actual message
2217 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
2218 const struct GNUNET_MessageHeader *message)
2220 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
2221 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
2230 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
2231 peer_id = ntohl (msg->peer_id);
2232 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2234 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2236 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2239 peer = peer_list[peer_id];
2240 if (GNUNET_YES == peer->is_remote)
2242 struct ForwardedOperationContext *fopc;
2244 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2245 GNUNET_SERVER_client_keep (client);
2246 fopc->client = client;
2247 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2249 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2250 fopc->operation_id, &msg->header,
2251 &forwarded_operation_reply_relay,
2253 fopc->timeout_task =
2254 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2256 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2260 GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->details.local.cfg,
2262 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
2263 GNUNET_free (config);
2266 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
2267 reply = GNUNET_realloc (xconfig, msize);
2268 (void) memmove (&reply[1], reply, xc_size);
2269 reply->header.size = htons (msize);
2270 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG);
2271 reply->peer_id = msg->peer_id;
2272 reply->operation_id = msg->operation_id;
2273 GNUNET_TESTING_peer_get_identity (peer_list[peer_id]->details.local.peer,
2274 &reply->peer_identity);
2275 reply->config_size = htons ((uint16_t) c_size);
2276 queue_message (client, &reply->header);
2277 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2282 * Task for cleaing up overlay connect context structure
2284 * @param cls the overlay connect context
2285 * @param tc the task context
2288 occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2290 struct OverlayConnectContext *occ = cls;
2292 LOG_DEBUG ("Cleaning up occ\n");
2293 GNUNET_free_non_null (occ->emsg);
2294 GNUNET_free_non_null (occ->hello);
2295 GNUNET_SERVER_client_drop (occ->client);
2296 if (NULL != occ->opc)
2297 GNUNET_TESTBED_forward_operation_msg_cancel_ (occ->opc);
2298 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2299 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2300 if (NULL != occ->ch)
2301 GNUNET_CORE_disconnect (occ->ch);
2302 if (NULL != occ->ghh)
2303 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2304 if (NULL != occ->p1th)
2305 GNUNET_TRANSPORT_disconnect (occ->p1th);
2306 if (NULL != occ->p2th)
2307 GNUNET_TRANSPORT_disconnect (occ->p2th);
2313 * Task which will be run when overlay connect request has been timed out
2315 * @param cls the OverlayConnectContext
2316 * @param tc the TaskContext
2319 timeout_overlay_connect (void *cls,
2320 const struct GNUNET_SCHEDULER_TaskContext *tc)
2322 struct OverlayConnectContext *occ = cls;
2324 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2325 send_operation_fail_msg (occ->client, occ->op_id, occ->emsg);
2326 occ_cleanup (occ, tc);
2332 * Function called to notify transport users that another
2333 * peer connected to us.
2335 * @param cls closure
2336 * @param new_peer the peer that connected
2337 * @param ats performance data
2338 * @param ats_count number of entries in ats (excluding 0-termination)
2341 overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2342 const struct GNUNET_ATS_Information *ats,
2343 unsigned int ats_count)
2345 struct OverlayConnectContext *occ = cls;
2346 struct GNUNET_TESTBED_ConnectionEventMessage *msg;
2348 char *other_peer_str;
2350 LOG_DEBUG ("Overlay connect notify\n");
2352 memcmp (new_peer, &occ->peer_identity,
2353 sizeof (struct GNUNET_PeerIdentity)))
2355 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer));
2356 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2358 memcmp (new_peer, &occ->other_peer_identity,
2359 sizeof (struct GNUNET_PeerIdentity)))
2361 LOG_DEBUG ("Unexpected peer %4s connected when expecting peer %4s\n",
2362 new_peer_str, other_peer_str);
2363 GNUNET_free (new_peer_str);
2364 GNUNET_free (other_peer_str);
2367 GNUNET_free (new_peer_str);
2368 LOG_DEBUG ("Peer %4s connected to peer %4s\n", other_peer_str,
2369 GNUNET_i2s (&occ->peer_identity));
2370 GNUNET_free (other_peer_str);
2371 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2373 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2374 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2376 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
2377 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2378 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2379 GNUNET_free_non_null (occ->emsg);
2381 if (NULL != occ->p2th)
2382 GNUNET_TRANSPORT_disconnect (occ->p2th);
2384 LOG_DEBUG ("Peers connected - Sending overlay connect success\n");
2385 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2387 htons (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2388 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT);
2389 msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
2390 msg->peer1 = htonl (occ->peer_id);
2391 msg->peer2 = htonl (occ->other_peer_id);
2392 msg->operation_id = GNUNET_htonll (occ->op_id);
2393 queue_message (occ->client, &msg->header);
2394 GNUNET_SCHEDULER_add_now (&occ_cleanup, occ);
2399 * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to
2402 * @param cls the OverlayConnectContext
2403 * @param tc the TaskContext from scheduler
2406 send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2408 struct OverlayConnectContext *occ = cls;
2409 char *other_peer_str;
2411 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2412 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2414 GNUNET_assert (NULL != occ->hello);
2415 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2416 if (NULL != occ->peer2_controller)
2418 struct GNUNET_TESTBED_RequestConnectMessage *msg;
2420 uint16_t hello_size;
2422 LOG_DEBUG ("Offering HELLO of %s to %s via Remote Overlay Request\n",
2423 GNUNET_i2s (&occ->peer_identity), other_peer_str);
2424 hello_size = ntohs (occ->hello->size);
2425 msize = sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hello_size;
2426 msg = GNUNET_malloc (msize);
2427 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT);
2428 msg->header.size = htons (msize);
2429 msg->peer = htonl (occ->other_peer_id);
2430 msg->operation_id = GNUNET_htonll (occ->op_id);
2431 (void) memcpy (&msg->peer_identity, &occ->peer_identity,
2432 sizeof (struct GNUNET_PeerIdentity));
2433 memcpy (msg->hello, occ->hello, hello_size);
2434 GNUNET_TESTBED_queue_message_ (occ->peer2_controller, &msg->header);
2438 LOG_DEBUG ("Offering HELLO of %s to %s\n",
2439 GNUNET_i2s (&occ->peer_identity), other_peer_str);
2440 GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL);
2441 GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity);
2442 occ->send_hello_task =
2443 GNUNET_SCHEDULER_add_delayed
2444 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
2445 100 * (pow (2, occ->retries++))),
2448 GNUNET_free (other_peer_str);
2452 * Test for checking whether HELLO message is empty
2454 * @param cls empty flag to set
2455 * @param address the HELLO
2456 * @param expiration expiration of the HELLO
2460 test_address (void *cls, const struct GNUNET_HELLO_Address *address,
2461 struct GNUNET_TIME_Absolute expiration)
2471 * Function called whenever there is an update to the HELLO of peers in the
2472 * OverlayConnectClosure. If we have a valid HELLO, we connect to the peer 2's
2473 * transport and offer peer 1's HELLO and ask peer 2 to connect to peer 1
2475 * @param cls closure
2476 * @param hello our updated HELLO
2479 hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2481 struct OverlayConnectContext *occ = cls;
2485 msize = ntohs (hello->size);
2487 (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *)
2488 hello, GNUNET_NO, &test_address,
2490 if (GNUNET_YES == empty)
2492 LOG_DEBUG ("HELLO of %s is empty\n", GNUNET_i2s (&occ->peer_identity));
2495 LOG_DEBUG ("Received HELLO of %s\n", GNUNET_i2s (&occ->peer_identity));
2496 occ->hello = GNUNET_malloc (msize);
2497 memcpy (occ->hello, hello, msize);
2498 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2500 GNUNET_TRANSPORT_disconnect (occ->p1th);
2502 GNUNET_free_non_null (occ->emsg);
2503 if (NULL == occ->peer2_controller)
2506 GNUNET_TRANSPORT_connect (peer_list[occ->other_peer_id]->details.local.cfg,
2507 &occ->other_peer_identity, NULL, NULL, NULL,
2509 if (NULL == occ->p2th)
2511 GNUNET_asprintf (&occ->emsg, "Cannot connect to TRANSPORT of %s\n",
2512 GNUNET_i2s (&occ->other_peer_identity));
2513 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2514 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2518 occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer");
2519 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
2524 * Function called after GNUNET_CORE_connect has succeeded (or failed
2525 * for good). Note that the private key of the peer is intentionally
2526 * not exposed here; if you need it, your process should try to read
2527 * the private key file directly (which should work if you are
2530 * @param cls closure
2531 * @param server handle to the server, NULL if we failed
2532 * @param my_identity ID of this peer, NULL if we failed
2535 core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
2536 const struct GNUNET_PeerIdentity *my_identity)
2538 struct OverlayConnectContext *occ = cls;
2540 GNUNET_free_non_null (occ->emsg);
2541 occ->emsg = GNUNET_strdup ("Failed to connect to CORE\n");
2542 if ((NULL == server) || (NULL == my_identity))
2544 GNUNET_free (occ->emsg);
2547 memcpy (&occ->peer_identity, my_identity,
2548 sizeof (struct GNUNET_PeerIdentity));
2550 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg,
2551 &occ->peer_identity, NULL, NULL, NULL, NULL);
2552 if (NULL == occ->p1th)
2554 GNUNET_asprintf (&occ->emsg, "Cannot connect to TRANSPORT of peers %4s",
2555 GNUNET_i2s (&occ->peer_identity));
2558 LOG_DEBUG ("Acquiring HELLO of peer %s\n", GNUNET_i2s (&occ->peer_identity));
2559 occ->emsg = GNUNET_strdup ("Timeout while acquiring HELLO message");
2560 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p1th, &hello_update_cb, occ);
2564 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2565 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2571 * Callback to be called when forwarded get peer config operation as part of
2572 * overlay connect is successfull. Connection to Peer 1's core is made and is
2573 * checked for new connection from peer 2
2575 * @param cls ForwardedOperationContext
2576 * @param msg the peer create success message
2579 overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg)
2581 struct OverlayConnectContext *occ = cls;
2582 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg;
2583 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2588 if (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG != ntohs (msg->type))
2590 cmsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
2592 memcpy (&occ->other_peer_identity, &cmsg->peer_identity,
2593 sizeof (struct GNUNET_PeerIdentity));
2594 GNUNET_free_non_null (occ->emsg);
2595 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2597 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2598 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2599 GNUNET_NO, no_handlers);
2600 if (NULL == occ->ch)
2605 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2607 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2612 * This callback is a part of overlay connect operation. This will be run when
2613 * the registration operation of peer2's controller is completed at peer1's
2616 * @param cls the ForwardedOverlayConnectContext
2617 * @param emsg the error message in case of any failure; NULL if host
2618 * registration is successfull.
2621 focc_reg_completion_cc (void *cls, const char *emsg)
2623 struct ForwardedOverlayConnectContext *focc = cls;
2624 struct GNUNET_CONFIGURATION_Handle *cfg;
2626 GNUNET_assert (FOCC_REGISTER == focc->state);
2627 focc->rhandle = NULL;
2628 GNUNET_assert (NULL == focc->sub_op);
2629 LOG_DEBUG ("Registering peer2's host successful\n");
2630 if ((NULL == focc->gateway2)
2631 || ((focc->peer2_host_id < slave_list_size) /* Check if we have the needed config */
2632 && (NULL != slave_list[focc->peer2_host_id])))
2634 focc->state = FOCC_LINK;
2635 cfg = (NULL == focc->gateway2) ?
2636 our_config : slave_list[focc->peer2_host_id]->cfg;
2638 GNUNET_TESTBED_controller_link_ (focc,
2640 focc->peer2_host_id,
2641 peer_list[focc->peer1]->details.remote.remote_host_id,
2646 focc->state = FOCC_GET_CFG;
2647 focc->sub_op = GNUNET_TESTBED_get_slave_config_ (focc, focc->gateway2,
2648 focc->peer2_host_id);
2653 * Callback to be called when forwarded overlay connection operation has a reply
2654 * from the sub-controller successfull. We have to relay the reply msg back to
2657 * @param cls ForwardedOperationContext
2658 * @param msg the peer create success message
2661 forwarded_overlay_connect_listener (void *cls,
2662 const struct GNUNET_MessageHeader *msg)
2664 struct ForwardedOperationContext *fopc = cls;
2665 struct ForwardedOverlayConnectContext *focc;
2670 forwarded_operation_reply_relay (cls, msg);
2673 switch (focc->state)
2676 if (GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG != ntohs (msg->type))
2678 GNUNET_break (0); /* Something failed; you may check output of
2680 cleanup_focc (focc);
2681 forwarded_operation_reply_relay (cls, msg);
2684 LOG_DEBUG ("Registering peer2's host\n");
2685 focc->state = FOCC_REGISTER;
2687 GNUNET_TESTBED_register_host (focc->gateway,
2688 host_list[focc->peer2_host_id],
2689 focc_reg_completion_cc, focc);
2694 GNUNET_SERVER_client_drop (fopc->client);
2695 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
2696 fopc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2702 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
2705 * @param client identification of the client
2706 * @param message the actual message
2709 handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
2710 const struct GNUNET_MessageHeader *message)
2712 const struct GNUNET_TESTBED_OverlayConnectMessage *msg;
2713 struct OverlayConnectContext *occ;
2714 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2718 uint64_t operation_id;
2721 uint32_t peer2_host_id;
2723 msg = (const struct GNUNET_TESTBED_OverlayConnectMessage *) message;
2724 p1 = ntohl (msg->peer1);
2725 p2 = ntohl (msg->peer2);
2726 peer2_host_id = ntohl (msg->peer2_host_id);
2727 GNUNET_assert (p1 < peer_list_size);
2728 GNUNET_assert (NULL != peer_list[p1]);
2729 peer = peer_list[p1];
2730 operation_id = GNUNET_ntohll (msg->operation_id);
2731 if (GNUNET_YES == peer->is_remote)
2733 struct ForwardedOperationContext *fopc;
2734 struct Route *route_to_peer2_host;
2735 struct Route *route_to_peer1_host;
2737 LOG_DEBUG ("Forwarding overlay connect\n");
2738 GNUNET_SERVER_client_keep (client);
2739 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2740 fopc->client = client;
2741 fopc->operation_id = operation_id;
2742 route_to_peer2_host = NULL;
2743 route_to_peer1_host = NULL;
2744 route_to_peer2_host = find_dest_route (peer2_host_id);
2745 if ((NULL != route_to_peer2_host)
2746 || (peer2_host_id == master_context->host_id))
2748 route_to_peer1_host =
2749 find_dest_route (peer_list[p1]->details.remote.remote_host_id);
2750 GNUNET_assert (NULL != route_to_peer1_host);
2751 if ((peer2_host_id == master_context->host_id)
2752 || (route_to_peer2_host->dest != route_to_peer1_host->dest))
2754 struct ForwardedOverlayConnectContext *focc;
2757 msize = sizeof (struct GNUNET_TESTBED_OverlayConnectMessage);
2758 focc = GNUNET_malloc (sizeof (struct ForwardedOverlayConnectContext));
2759 focc->gateway = peer->details.remote.controller;
2760 focc->gateway2 = (NULL == route_to_peer2_host) ? NULL :
2761 slave_list[route_to_peer2_host->dest]->controller;
2764 focc->peer2_host_id = peer2_host_id;
2765 focc->state = FOCC_INIT;
2766 focc->orig_msg = GNUNET_malloc (msize);
2767 (void) memcpy (focc->orig_msg, message, msize);
2768 GNUNET_SERVER_client_keep (client);
2769 focc->client = client;
2770 focc->operation_id = operation_id;
2775 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2776 operation_id, message,
2777 &forwarded_overlay_connect_listener,
2779 fopc->timeout_task =
2780 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2782 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2785 occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
2786 GNUNET_SERVER_client_keep (client);
2787 occ->client = client;
2789 occ->other_peer_id = p2;
2790 occ->peer = peer_list[p1];
2791 occ->op_id = GNUNET_ntohll (msg->operation_id);
2792 if ((p2 >= peer_list_size) || (NULL == peer_list[p2]))
2794 if ((peer2_host_id >= slave_list_size)
2795 || (NULL ==slave_list[peer2_host_id]))
2797 struct GNUNET_TESTBED_NeedControllerConfig *reply;
2800 reply = GNUNET_malloc (sizeof (struct
2801 GNUNET_TESTBED_NeedControllerConfig));
2802 reply->header.size = htons (sizeof (struct
2803 GNUNET_TESTBED_NeedControllerConfig));
2804 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG);
2805 reply->controller_host_id = msg->peer2_host_id;
2806 reply->operation_id = msg->operation_id;
2807 queue_message (client, &reply->header);
2808 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2813 occ->peer2_controller = slave_list[peer2_host_id]->controller;
2814 if (NULL == occ->peer2_controller)
2816 GNUNET_break (0); /* What's going on? */
2817 GNUNET_SERVER_client_drop (client);
2819 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2826 if (GNUNET_YES == peer_list[occ->other_peer_id]->is_remote)
2827 occ->peer2_controller = peer_list[occ->other_peer_id]->details.remote.controller;
2829 /* Get the identity of the second peer */
2830 if (NULL != occ->peer2_controller)
2832 struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg;
2835 htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
2836 cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG);
2837 cmsg.peer_id = msg->peer2;
2838 cmsg.operation_id = msg->operation_id;
2840 GNUNET_TESTBED_forward_operation_msg_ (occ->peer2_controller,
2841 occ->op_id, &cmsg.header,
2842 &overlay_connect_get_config,
2845 GNUNET_strdup ("Timeout while getting peer identity of peer B\n");
2847 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2848 (GNUNET_TIME_UNIT_SECONDS, 30),
2849 &timeout_overlay_connect, occ);
2850 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2853 GNUNET_TESTING_peer_get_identity (peer_list[occ->other_peer_id]->details.local.peer,
2854 &occ->other_peer_identity);
2855 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */
2856 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2858 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2859 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2860 GNUNET_NO, no_handlers);
2861 if (NULL == occ->ch)
2863 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2866 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2867 (GNUNET_TIME_UNIT_SECONDS, 30),
2868 &timeout_overlay_connect, occ);
2869 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2874 * Function to cleanup RequestOverlayConnectContext and any associated tasks
2877 * @param rocc the RequestOverlayConnectContext
2880 cleanup_rocc (struct RequestOverlayConnectContext *rocc)
2882 if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id)
2883 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
2884 if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id)
2885 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id);
2886 GNUNET_TRANSPORT_disconnect (rocc->th);
2887 GNUNET_free_non_null (rocc->hello);
2893 * Task to timeout rocc and cleanit up
2895 * @param cls the RequestOverlayConnectContext
2896 * @param tc the TaskContext from scheduler
2899 timeout_rocc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2901 struct RequestOverlayConnectContext *rocc = cls;
2903 rocc->timeout_rocc_task_id = GNUNET_SCHEDULER_NO_TASK;
2904 cleanup_rocc (rocc);
2909 * Function called to notify transport users that another
2910 * peer connected to us.
2912 * @param cls closure
2913 * @param new_peer the peer that connected
2914 * @param ats performance data
2915 * @param ats_count number of entries in ats (excluding 0-termination)
2918 transport_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2919 const struct GNUNET_ATS_Information * ats,
2922 struct RequestOverlayConnectContext *rocc = cls;
2924 LOG_DEBUG ("Request Overlay connect notify\n");
2925 if (0 != memcmp (new_peer, &rocc->a_id, sizeof (struct GNUNET_PeerIdentity)))
2927 LOG_DEBUG ("Peer %4s connected\n", GNUNET_i2s (&rocc->a_id));
2928 cleanup_rocc (rocc);
2933 * Task to offer the HELLO message to the peer and ask it to connect to the peer
2934 * whose identity is in RequestOverlayConnectContext
2936 * @param cls the RequestOverlayConnectContext
2937 * @param tc the TaskContext from scheduler
2940 attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2942 struct RequestOverlayConnectContext *rocc = cls;
2944 rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK;
2945 GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, NULL, NULL);
2946 GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id);
2947 rocc->attempt_connect_task_id =
2948 GNUNET_SCHEDULER_add_delayed
2949 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
2950 100 * (pow (2, rocc->retries++))),
2951 &attempt_connect_task, rocc);
2956 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages
2959 * @param client identification of the client
2960 * @param message the actual message
2963 handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
2964 const struct GNUNET_MessageHeader *message)
2966 const struct GNUNET_TESTBED_RequestConnectMessage *msg;
2967 struct RequestOverlayConnectContext *rocc;
2973 msize = ntohs (message->size);
2974 if (sizeof (struct GNUNET_TESTBED_RequestConnectMessage) >= msize)
2977 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2980 msg = (const struct GNUNET_TESTBED_RequestConnectMessage *) message;
2981 if ((NULL == msg->hello) ||
2982 (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type)))
2985 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2988 hsize = ntohs (msg->hello->size);
2989 if ((sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hsize) != msize)
2992 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2995 peer_id = ntohl (msg->peer);
2996 if ((peer_id >= peer_list_size) || (NULL == (peer = peer_list[peer_id])))
2998 GNUNET_break_op (0);
2999 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3002 if (GNUNET_YES == peer->is_remote)
3004 struct GNUNET_MessageHeader *msg2;
3006 msg2 = GNUNET_malloc (msize);
3007 (void) memcpy (msg2, message, msize);
3008 GNUNET_TESTBED_queue_message_ (peer->details.remote.controller, msg2);
3009 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3012 rocc = GNUNET_malloc (sizeof (struct RequestOverlayConnectContext));
3013 rocc->th = GNUNET_TRANSPORT_connect (peer->details.local.cfg, NULL, rocc,
3014 NULL, &transport_connect_notify, NULL);
3015 if (NULL == rocc->th)
3019 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3022 memcpy (&rocc->a_id, &msg->peer_identity,
3023 sizeof (struct GNUNET_PeerIdentity));
3024 rocc->hello = GNUNET_malloc (hsize);
3025 memcpy (rocc->hello, msg->hello, hsize);
3026 rocc->attempt_connect_task_id =
3027 GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
3028 rocc->timeout_rocc_task_id =
3029 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc);
3030 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3035 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
3038 * @param client identification of the client
3039 * @param message the actual message
3042 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
3043 const struct GNUNET_MessageHeader *message)
3045 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
3046 struct Slave *slave;
3047 struct GNUNET_TESTBED_SlaveConfiguration *reply;
3051 size_t xconfig_size;
3056 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
3057 slave_id = ntohl (msg->slave_id);
3058 op_id = GNUNET_ntohll (msg->operation_id);
3059 if ((slave_list_size <= slave_id) || (NULL == slave_list[slave_id]))
3061 send_operation_fail_msg (client, op_id, "Slave not found");
3062 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3065 slave = slave_list[slave_id];
3066 if (NULL == slave->cfg)
3068 send_operation_fail_msg (client, op_id,
3069 "Configuration not found (slave not started by me)");
3070 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3073 config = GNUNET_CONFIGURATION_serialize (slave->cfg, &config_size);
3074 xconfig_size = GNUNET_TESTBED_compress_config_ (config, config_size,
3076 GNUNET_free (config);
3077 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
3078 GNUNET_break (reply_size <= UINT16_MAX);
3079 GNUNET_break (config_size <= UINT16_MAX);
3080 reply = GNUNET_realloc (xconfig, reply_size);
3081 (void) memmove (&reply[1], reply, xconfig_size);
3082 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG);
3083 reply->header.size = htons ((uint16_t) reply_size);
3084 reply->slave_id = msg->slave_id;
3085 reply->operation_id = msg->operation_id;
3086 reply->config_size = htons ((uint16_t) config_size);
3087 queue_message (client, &reply->header);
3088 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3093 * Iterator over hash map entries.
3095 * @param cls closure
3096 * @param key current key code
3097 * @param value value in the hash map
3098 * @return GNUNET_YES if we should continue to
3103 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
3105 struct SharedService *ss = value;
3107 GNUNET_assert (GNUNET_YES ==
3108 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
3109 GNUNET_free (ss->name);
3116 * Task to clean up and shutdown nicely
3119 * @param tc the TaskContext from scheduler
3122 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3124 struct LCFContextQueue *lcfq;
3127 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
3128 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
3129 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
3131 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
3132 if (NULL != lcfq_head)
3134 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
3136 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
3137 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
3139 if (NULL != lcfq_head->lcf->rhandle)
3140 GNUNET_TESTBED_cancel_registration (lcfq_head->lcf->rhandle);
3142 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
3143 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
3145 GNUNET_free (lcfq->lcf->msg);
3146 GNUNET_free (lcfq->lcf);
3147 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
3150 /* Clear peer list */
3151 for (id = 0; id < peer_list_size; id++)
3152 if (NULL != peer_list[id])
3154 if (GNUNET_NO == peer_list[id]->is_remote)
3156 if (GNUNET_YES == peer_list[id]->details.local.is_running)
3157 GNUNET_TESTING_peer_stop (peer_list[id]->details.local.peer);
3158 GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
3159 GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
3161 GNUNET_free (peer_list[id]);
3163 GNUNET_free_non_null (peer_list);
3164 /* Clear host list */
3165 for (id = 0; id < host_list_size; id++)
3166 if (NULL != host_list[id])
3167 GNUNET_TESTBED_host_destroy (host_list[id]);
3168 GNUNET_free_non_null (host_list);
3169 /* Clear route list */
3170 for (id = 0; id < route_list_size; id++)
3171 if (NULL != route_list[id])
3172 GNUNET_free (route_list[id]);
3173 GNUNET_free_non_null (route_list);
3174 /* Clear slave_list */
3175 for (id = 0; id < slave_list_size; id++)
3176 if (NULL != slave_list[id])
3178 if (NULL != slave_list[id]->cfg)
3179 GNUNET_CONFIGURATION_destroy (slave_list[id]->cfg);
3180 if (NULL != slave_list[id]->controller)
3181 GNUNET_TESTBED_controller_disconnect (slave_list[id]->controller);
3182 if (NULL != slave_list[id]->controller_proc)
3183 GNUNET_TESTBED_controller_stop (slave_list[id]->controller_proc);
3184 GNUNET_free (slave_list[id]);
3186 GNUNET_free_non_null (slave_list);
3187 if (NULL != master_context)
3189 GNUNET_free_non_null (master_context->master_ip);
3190 if (NULL != master_context->system)
3191 GNUNET_TESTING_system_destroy (master_context->system, GNUNET_YES);
3192 GNUNET_free (master_context);
3193 master_context = NULL;
3195 GNUNET_free_non_null (hostname);
3196 GNUNET_CONFIGURATION_destroy (our_config);
3201 * Callback for client disconnect
3204 * @param client the client which has disconnected
3207 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
3209 if (NULL == master_context)
3211 if (client == master_context->client)
3213 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
3214 GNUNET_SERVER_client_drop (client);
3215 /* should not be needed as we're terminated by failure to read
3216 * from stdin, but if stdin fails for some reason, this shouldn't
3217 * hurt for now --- might need to revise this later if we ever
3218 * decide that master connections might be temporarily down
3219 * for some reason */
3220 //GNUNET_SCHEDULER_shutdown ();
3228 * @param cls closure
3229 * @param server the initialized server
3230 * @param cfg configuration to use
3233 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
3234 const struct GNUNET_CONFIGURATION_Handle *cfg)
3236 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
3237 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
3238 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
3239 {&handle_configure_shared_service, NULL,
3240 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
3241 {&handle_link_controllers, NULL,
3242 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
3243 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
3244 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER,
3245 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
3246 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER,
3247 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
3248 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER,
3249 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
3250 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG,
3251 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
3252 {&handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT,
3253 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
3254 {&handle_overlay_request_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT,
3256 {handle_slave_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG,
3257 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
3261 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
3262 (cfg, "testbed", "HOSTNAME", &hostname));
3263 our_config = GNUNET_CONFIGURATION_dup (cfg);
3264 GNUNET_SERVER_add_handlers (server, message_handlers);
3265 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
3266 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
3268 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
3269 &shutdown_task, NULL);
3270 LOG_DEBUG ("Testbed startup complete\n");
3271 event_mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
3276 * The starting point of execution
3279 main (int argc, char *const *argv)
3281 //sleep (15); /* Debugging */
3282 return (GNUNET_OK ==
3283 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
3284 &testbed_run, NULL)) ? 0 : 1;
3287 /* end of gnunet-service-testbed.c */