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 * Id of the timeout task;
584 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
587 * Enumeration of states for this context
597 * State where we attempt to register peer2's controller with peer1's controller
602 * State where we attempt to get peer2's controller configuration
607 * State where we attempt to link the controller of peer 1 to the controller
613 * State where we attempt to do the overlay connection again
630 * Id of the host where peer2 is running
632 uint32_t peer2_host_id;
638 * The master context; generated with the first INIT message
640 static struct Context *master_context;
643 * Our hostname; we give this to all the peers we start
645 static char *hostname;
655 static struct GNUNET_CONFIGURATION_Handle *our_config;
658 * Current Transmit Handle; NULL if no notify transmit exists currently
660 static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
667 * The head for the LCF queue
669 static struct LCFContextQueue *lcfq_head;
672 * The tail for the LCF queue
674 static struct LCFContextQueue *lcfq_tail;
677 * The message queue head
679 static struct MessageQueue *mq_head;
682 * The message queue tail
684 static struct MessageQueue *mq_tail;
689 static struct GNUNET_TESTBED_Host **host_list;
694 static struct Route **route_list;
697 * A list of directly linked neighbours
699 static struct Slave **slave_list;
702 * A list of peers we know about
704 static struct Peer **peer_list;
707 * The hashmap of shared services
709 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
712 * The event mask for the events we listen from sub-controllers
714 static uint64_t event_mask;
717 * The size of the host list
719 static uint32_t host_list_size;
722 * The size of the route list
724 static uint32_t route_list_size;
727 * The size of directly linked neighbours list
729 static uint32_t slave_list_size;
732 * The size of the peer list
734 static uint32_t peer_list_size;
741 * The lcf_task handle
743 static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
746 * The shutdown task handle
748 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
752 * Function called to notify a client about the connection begin ready to queue
753 * more data. "buf" will be NULL and "size" zero if the connection was closed
754 * for writing in the meantime.
757 * @param size number of bytes available in buf
758 * @param buf where the callee should write the message
759 * @return number of bytes written to buf
762 transmit_ready_notify (void *cls, size_t size, void *buf)
764 struct MessageQueue *mq_entry;
766 transmit_handle = NULL;
768 GNUNET_assert (NULL != mq_entry);
771 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
772 size = ntohs (mq_entry->msg->size);
773 memcpy (buf, mq_entry->msg, size);
774 GNUNET_free (mq_entry->msg);
775 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
776 GNUNET_free (mq_entry);
778 if (NULL != mq_entry)
780 GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
781 ntohs (mq_entry->msg->size),
782 GNUNET_TIME_UNIT_FOREVER_REL,
783 &transmit_ready_notify, NULL);
789 * Queues a message in send queue for sending to the service
791 * @param client the client to whom the queued message has to be sent
792 * @param msg the message to queue
795 queue_message (struct GNUNET_SERVER_Client *client,
796 struct GNUNET_MessageHeader *msg)
798 struct MessageQueue *mq_entry;
802 type = ntohs (msg->type);
803 size = ntohs (msg->size);
804 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
805 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
806 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
808 mq_entry->client = client;
809 LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type,
811 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
812 if (NULL == transmit_handle)
814 GNUNET_SERVER_notify_transmit_ready (client, size,
815 GNUNET_TIME_UNIT_FOREVER_REL,
816 &transmit_ready_notify, NULL);
821 * Similar to GNUNET_realloc; however clears tail part of newly allocated memory
823 * @param ptr the memory block to realloc
824 * @param size the size of ptr
825 * @param new_size the size to which ptr has to be realloc'ed
826 * @return the newly reallocated memory block
829 TESTBED_realloc (void *ptr, size_t size, size_t new_size)
831 ptr = GNUNET_realloc (ptr, new_size);
833 (void) memset (ptr + size, 0, new_size - size);
839 * Function to add a host to the current list of known hosts
841 * @param host the host to add
842 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
846 host_list_add (struct GNUNET_TESTBED_Host *host)
851 host_id = GNUNET_TESTBED_host_get_id_ (host);
852 orig_size = host_list_size;
853 if (host_list_size <= host_id)
855 while (host_list_size <= host_id)
856 host_list_size += LIST_GROW_STEP;
858 TESTBED_realloc (host_list,
859 sizeof (struct GNUNET_TESTBED_Host *) * orig_size,
860 sizeof (struct GNUNET_TESTBED_Host *)
863 if (NULL != host_list[host_id])
865 LOG_DEBUG ("A host with id: %u already exists\n", host_id);
866 return GNUNET_SYSERR;
868 host_list[host_id] = host;
874 * Adds a route to the route list
876 * @param route the route to add
879 route_list_add (struct Route *route)
883 orig_size = route_list_size;
884 if (route->dest >= route_list_size)
886 while (route->dest >= route_list_size)
887 route_list_size += LIST_GROW_STEP;
889 TESTBED_realloc (route_list,
890 sizeof (struct Route *) * orig_size,
891 sizeof (struct Route *) * route_list_size);
893 GNUNET_assert (NULL == route_list[route->dest]);
894 route_list[route->dest] = route;
899 * Adds a slave to the slave array
901 * @param slave the slave controller to add
904 slave_list_add (struct Slave *slave)
906 if (slave->host_id >= slave_list_size)
909 TESTBED_realloc (slave_list, sizeof (struct Slave *) * slave_list_size,
910 sizeof (struct Slave *) * (slave_list_size +
912 slave_list_size += LIST_GROW_STEP;
914 GNUNET_assert (NULL == slave_list[slave->host_id]);
915 slave_list[slave->host_id] = slave;
920 * Adds a peer to the peer array
922 * @param peer the peer to add
925 peer_list_add (struct Peer *peer)
929 orig_size = peer_list_size;
930 if (peer->id >= peer_list_size)
932 while (peer->id >= peer_list_size)
933 peer_list_size += LIST_GROW_STEP;
935 TESTBED_realloc (peer_list, sizeof (struct Peer *) * orig_size,
936 sizeof (struct Peer *) * peer_list_size);
938 GNUNET_assert (NULL == peer_list[peer->id]);
939 peer_list[peer->id] = peer;
944 * Removes a the give peer from the peer array
946 * @param peer the peer to be removed
949 peer_list_remove (struct Peer *peer)
954 peer_list[peer->id] = NULL;
955 orig_size = peer_list_size;
956 while (peer_list_size >= LIST_GROW_STEP)
958 for (id = peer_list_size - 1;
959 (id >= peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); id--)
960 if (NULL != peer_list[id])
962 if (id != ((peer_list_size - LIST_GROW_STEP) - 1))
964 peer_list_size -= LIST_GROW_STEP;
966 if (orig_size == peer_list_size)
969 GNUNET_realloc (peer_list, sizeof (struct Peer *) * peer_list_size);
974 * Finds the route with directly connected host as destination through which
975 * the destination host can be reached
977 * @param host_id the id of the destination host
978 * @return the route with directly connected destination host; NULL if no route
981 static struct Route *
982 find_dest_route (uint32_t host_id)
986 if (route_list_size <= host_id)
988 while (NULL != (route = route_list[host_id]))
990 if (route->thru == master_context->host_id)
992 host_id = route->thru;
999 * Routes message to a host given its host_id
1001 * @param host_id the id of the destination host
1002 * @param msg the message to be routed
1005 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
1012 * Send operation failure message to client
1014 * @param client the client to which the failure message has to be sent to
1015 * @param operation_id the id of the failed operation
1016 * @param emsg the error message; can be NULL
1019 send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
1020 uint64_t operation_id, const char *emsg)
1022 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
1026 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
1027 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
1029 msg = GNUNET_malloc (msize);
1030 msg->header.size = htons (msize);
1031 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONFAILEVENT);
1032 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
1033 msg->operation_id = GNUNET_htonll (operation_id);
1035 memcpy (&msg[1], emsg, emsg_len);
1036 queue_message (client, &msg->header);
1041 * Function to send generic operation success message to given client
1043 * @param client the client to send the message to
1044 * @param operation_id the id of the operation which was successful
1047 send_operation_success_msg (struct GNUNET_SERVER_Client *client,
1048 uint64_t operation_id)
1050 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
1053 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
1054 msg = GNUNET_malloc (msize);
1055 msg->header.size = htons (msize);
1056 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
1057 msg->operation_id = GNUNET_htonll (operation_id);
1058 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
1059 queue_message (client, &msg->header);
1064 * The Link Controller forwarding task
1066 * @param cls the LCFContext
1067 * @param tc the Task context from scheduler
1070 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1074 * Completion callback for host registrations while forwarding Link Controller messages
1076 * @param cls the LCFContext
1077 * @param emsg the error message; NULL if host registration is successful
1080 lcf_proc_cc (void *cls, const char *emsg)
1082 struct LCFContext *lcf = cls;
1084 lcf->rhandle = NULL;
1085 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1090 goto registration_error;
1091 lcf->state = DELEGATED_HOST_REGISTERED;
1092 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1094 case DELEGATED_HOST_REGISTERED:
1096 goto registration_error;
1097 lcf->state = SLAVE_HOST_REGISTERED;
1098 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1101 GNUNET_assert (0); /* Shouldn't reach here */
1106 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
1108 lcf->state = FINISHED;
1109 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1114 * Callback to be called when forwarded link controllers operation is
1115 * successfull. We have to relay the reply msg back to the client
1117 * @param cls ForwardedOperationContext
1118 * @param msg the peer create success message
1121 forwarded_operation_reply_relay (void *cls,
1122 const struct GNUNET_MessageHeader *msg)
1124 struct ForwardedOperationContext *fopc = cls;
1125 struct GNUNET_MessageHeader *dup_msg;
1128 msize = ntohs (msg->size);
1129 LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type),
1131 dup_msg = GNUNET_malloc (msize);
1132 (void) memcpy (dup_msg, msg, msize);
1133 queue_message (fopc->client, dup_msg);
1134 GNUNET_SERVER_client_drop (fopc->client);
1135 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
1141 * Task to free resources when forwarded link controllers has been timedout
1143 * @param cls the ForwardedOperationContext
1144 * @param tc the task context from scheduler
1147 forwarded_operation_timeout (void *cls,
1148 const struct GNUNET_SCHEDULER_TaskContext *tc)
1150 struct ForwardedOperationContext *fopc = cls;
1152 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
1153 send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
1154 GNUNET_SERVER_client_drop (fopc->client);
1160 * The Link Controller forwarding task
1162 * @param cls the LCFContext
1163 * @param tc the Task context from scheduler
1166 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1168 struct LCFContext *lcf = cls;
1169 struct LCFContextQueue *lcfq;
1170 struct ForwardedOperationContext *fopc;
1172 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
1177 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id],
1178 lcf->gateway->controller))
1181 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1182 host_list[lcf->delegated_host_id],
1187 lcf->state = DELEGATED_HOST_REGISTERED;
1188 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1191 case DELEGATED_HOST_REGISTERED:
1193 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id],
1194 lcf->gateway->controller))
1197 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1198 host_list[lcf->slave_host_id],
1203 lcf->state = SLAVE_HOST_REGISTERED;
1204 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1207 case SLAVE_HOST_REGISTERED:
1208 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1209 fopc->client = lcf->client;
1210 fopc->operation_id = lcf->operation_id;
1212 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
1215 &forwarded_operation_reply_relay,
1217 fopc->timeout_task =
1218 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1220 lcf->state = FINISHED;
1221 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1225 GNUNET_assert (lcfq->lcf == lcf);
1226 GNUNET_free (lcf->msg);
1228 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
1230 if (NULL != lcfq_head)
1232 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
1238 * Callback to be called when forwarded overlay connection operation has a reply
1239 * from the sub-controller successfull. We have to relay the reply msg back to
1242 * @param cls ForwardedOperationContext
1243 * @param msg the peer create success message
1246 forwarded_overlay_connect_listener (void *cls,
1247 const struct GNUNET_MessageHeader *msg);
1251 * Cleans up ForwardedOverlayConnectContext
1253 * @param focc the ForwardedOverlayConnectContext to cleanup
1256 cleanup_focc (struct ForwardedOverlayConnectContext *focc)
1258 if (GNUNET_SCHEDULER_NO_TASK != focc->timeout_task)
1259 GNUNET_SCHEDULER_cancel (focc->timeout_task);
1260 if (NULL != focc->sub_op)
1261 GNUNET_TESTBED_operation_done (focc->sub_op);
1262 if (NULL != focc->client)
1263 GNUNET_SERVER_client_drop (focc->client);
1264 GNUNET_free_non_null (focc->orig_msg);
1269 * Callback for event from slave controllers
1271 * @param cls struct Slave *
1272 * @param event information about the event
1275 slave_event_callback (void *cls,
1276 const struct GNUNET_TESTBED_EventInformation *event)
1278 struct ForwardedOverlayConnectContext *focc;
1279 struct ForwardedOperationContext *fopc;
1280 struct GNUNET_CONFIGURATION_Handle *slave_cfg;
1281 struct GNUNET_TESTBED_Operation *old_op;
1284 /* We currently only get here when doing overlay connect operations and that
1285 too while trying out sub operations */
1286 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
1287 focc = event->details.operation_finished.op_cls;
1288 LOG_DEBUG ("Operation successful\n");
1289 if (NULL != event->details.operation_finished.emsg)
1291 GNUNET_asprintf (&emsg, "Failure executing suboperation: %s",
1292 event->details.operation_finished.emsg);
1293 send_operation_fail_msg (focc->client, focc->operation_id,
1296 cleanup_focc (focc);
1299 switch (focc->state)
1302 slave_cfg = event->details.operation_finished.generic;
1303 old_op = focc->sub_op;
1304 focc->state = FOCC_LINK;
1305 focc->sub_op = GNUNET_TESTBED_controller_link_ (focc,
1307 focc->peer2_host_id,
1308 peer_list[focc->peer1]->details.remote.remote_host_id,
1311 GNUNET_TESTBED_operation_done (old_op);
1314 LOG_DEBUG ("OL: Linking controllers successfull\n");
1315 GNUNET_TESTBED_operation_done (focc->sub_op);
1316 focc->sub_op = NULL;
1317 focc->state = FOCC_OL_CONNECT;
1318 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1319 fopc->client = focc->client;
1320 focc->client = NULL;
1321 fopc->operation_id = focc->operation_id;
1324 GNUNET_TESTBED_forward_operation_msg_ (focc->gateway,
1325 focc->operation_id, focc->orig_msg,
1326 &forwarded_operation_reply_relay,
1328 GNUNET_free (focc->orig_msg);
1329 focc->orig_msg = NULL;
1330 fopc->timeout_task =
1331 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1333 cleanup_focc (focc);
1343 * Callback to signal successfull startup of the controller process
1345 * @param cls the handle to the slave whose status is to be found here
1346 * @param cfg the configuration with which the controller has been started;
1347 * NULL if status is not GNUNET_OK
1348 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
1349 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1352 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
1355 struct Slave *slave = cls;
1356 struct LinkControllersContext *lcc;
1359 if (GNUNET_SYSERR == status)
1361 slave->controller_proc = NULL;
1362 slave_list[slave->host_id] = NULL;
1363 if (NULL != slave->cfg)
1364 GNUNET_CONFIGURATION_destroy (slave->cfg);
1365 GNUNET_free (slave);
1367 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
1368 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
1372 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1374 &slave_event_callback, slave);
1375 if (NULL != slave->controller)
1377 send_operation_success_msg (lcc->client, lcc->operation_id);
1378 slave->cfg = GNUNET_CONFIGURATION_dup (cfg);
1382 send_operation_fail_msg (lcc->client, lcc->operation_id,
1383 "Could not connect to delegated controller");
1384 GNUNET_TESTBED_controller_stop (slave->controller_proc);
1385 slave_list[slave->host_id] = NULL;
1386 GNUNET_free (slave);
1393 if (NULL != lcc->client)
1395 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
1396 GNUNET_SERVER_client_drop (lcc->client);
1407 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
1410 * @param client identification of the client
1411 * @param message the actual message
1414 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
1415 const struct GNUNET_MessageHeader *message)
1417 const struct GNUNET_TESTBED_InitMessage *msg;
1418 struct GNUNET_TESTBED_Host *host;
1419 const char *controller_hostname;
1422 if (NULL != master_context)
1424 LOG_DEBUG ("We are being connected to laterally\n");
1425 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1428 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
1429 msize = ntohs (message->size);
1430 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
1433 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1436 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
1437 controller_hostname = (const char *) &msg[1];
1438 if ('\0' != controller_hostname[msize - 1])
1441 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1444 master_context = GNUNET_malloc (sizeof (struct Context));
1445 master_context->client = client;
1446 master_context->host_id = ntohl (msg->host_id);
1447 master_context->master_ip = GNUNET_strdup (controller_hostname);
1448 LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip);
1449 master_context->system =
1450 GNUNET_TESTING_system_create ("testbed", master_context->master_ip, hostname);
1452 GNUNET_TESTBED_host_create_with_id (master_context->host_id,
1453 master_context->master_ip,
1456 host_list_add (host);
1457 GNUNET_SERVER_client_keep (client);
1458 LOG_DEBUG ("Created master context with host ID: %u\n",
1459 master_context->host_id);
1460 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1465 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1468 * @param client identification of the client
1469 * @param message the actual message
1472 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
1473 const struct GNUNET_MessageHeader *message)
1475 struct GNUNET_TESTBED_Host *host;
1476 const struct GNUNET_TESTBED_AddHostMessage *msg;
1477 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
1482 uint16_t username_length;
1483 uint16_t hostname_length;
1484 uint16_t reply_size;
1487 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
1488 msize = ntohs (msg->header.size);
1489 username = (char *) &msg[1];
1490 username_length = ntohs (msg->user_name_length);
1491 if (0 != username_length)
1493 /* msg must contain hostname */
1494 GNUNET_assert (msize > (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
1495 username_length + 1));
1496 if (0 != username_length)
1497 GNUNET_assert ('\0' == username[username_length - 1]);
1498 hostname = username + username_length;
1500 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
1501 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
1502 GNUNET_assert (strlen (hostname) == hostname_length - 1);
1503 host_id = ntohl (msg->host_id);
1504 LOG_DEBUG ("Received ADDHOST message\n");
1505 LOG_DEBUG ("-------host id: %u\n", host_id);
1506 LOG_DEBUG ("-------hostname: %s\n", hostname);
1507 if (0 != username_length)
1508 LOG_DEBUG ("-------username: %s\n", username);
1511 LOG_DEBUG ("-------username: NULL\n");
1514 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1516 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1517 ntohs (msg->ssh_port));
1518 GNUNET_assert (NULL != host);
1519 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1520 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1521 if (GNUNET_OK != host_list_add (host))
1523 /* We are unable to add a host */
1524 emsg = "A host exists with given host-id";
1525 LOG_DEBUG ("%s: %u", emsg, host_id);
1526 GNUNET_TESTBED_host_destroy (host);
1527 reply_size += strlen (emsg) + 1;
1528 reply = GNUNET_malloc (reply_size);
1529 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1532 reply = GNUNET_malloc (reply_size);
1533 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
1534 reply->header.size = htons (reply_size);
1535 reply->host_id = htonl (host_id);
1536 queue_message (client, &reply->header);
1541 * Iterator over hash map entries.
1543 * @param cls closure
1544 * @param key current key code
1545 * @param value value in the hash map
1546 * @return GNUNET_YES if we should continue to
1551 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1553 struct SharedService *queried_ss = cls;
1554 struct SharedService *ss = value;
1556 if (0 == strcmp (ss->name, queried_ss->name))
1564 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1567 * @param client identification of the client
1568 * @param message the actual message
1571 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1572 const struct GNUNET_MessageHeader *message)
1574 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1575 struct SharedService *ss;
1577 struct GNUNET_HashCode hash;
1579 uint16_t service_name_size;
1581 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1582 msg_size = ntohs (message->size);
1583 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1586 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1590 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1591 service_name = (char *) &msg[1];
1592 if ('\0' != service_name[service_name_size - 1])
1595 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1598 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1599 service_name, ntohl (msg->num_peers));
1600 if (ntohl (msg->host_id) != master_context->host_id)
1602 route_message (ntohl (msg->host_id), message);
1603 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1606 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1607 ss = GNUNET_malloc (sizeof (struct SharedService));
1608 ss->name = strdup (service_name);
1609 ss->num_shared = ntohl (msg->num_peers);
1610 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1611 if (GNUNET_SYSERR ==
1612 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1613 &ss_exists_iterator, ss))
1615 LOG (GNUNET_ERROR_TYPE_WARNING,
1616 "Service %s already configured as a shared service. "
1617 "Ignoring service sharing request \n", ss->name);
1618 GNUNET_free (ss->name);
1622 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1623 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1628 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1631 * @param client identification of the client
1632 * @param message the actual message
1635 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1636 const struct GNUNET_MessageHeader *message)
1638 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1639 struct GNUNET_CONFIGURATION_Handle *cfg;
1640 struct LCFContextQueue *lcfq;
1641 struct Route *route;
1642 struct Route *new_route;
1646 uint32_t delegated_host_id;
1647 uint32_t slave_host_id;
1650 if (NULL == master_context)
1653 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1656 msize = ntohs (message->size);
1657 if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
1660 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1663 msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
1664 delegated_host_id = ntohl (msg->delegated_host_id);
1665 if (delegated_host_id == master_context->host_id)
1668 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1669 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1672 if ((delegated_host_id >= host_list_size) ||
1673 (NULL == host_list[delegated_host_id]))
1675 LOG (GNUNET_ERROR_TYPE_WARNING,
1676 "Delegated host %u not registered with us\n", delegated_host_id);
1677 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1680 slave_host_id = ntohl (msg->slave_host_id);
1681 if ((slave_host_id >= host_list_size) || (NULL == host_list[slave_host_id]))
1683 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n",
1685 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1688 if (slave_host_id == delegated_host_id)
1690 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1691 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1695 if (slave_host_id == master_context->host_id) /* Link from us */
1697 struct Slave *slave;
1698 struct LinkControllersContext *lcc;
1700 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1701 config_size = ntohs (msg->config_size);
1702 if ((delegated_host_id < slave_list_size) && (NULL != slave_list[delegated_host_id])) /* We have already added */
1704 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1706 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1709 config = GNUNET_malloc (config_size);
1710 dest_size = (uLongf) config_size;
1712 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1715 GNUNET_break (0); /* Compression error */
1716 GNUNET_free (config);
1717 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1720 if (config_size != dest_size)
1722 LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1723 GNUNET_free (config);
1724 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1727 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1729 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1731 GNUNET_break (0); /* Configuration parsing error */
1732 GNUNET_free (config);
1733 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1736 GNUNET_free (config);
1737 if ((delegated_host_id < slave_list_size) &&
1738 (NULL != slave_list[delegated_host_id]))
1740 GNUNET_break (0); /* Configuration parsing error */
1741 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1744 slave = GNUNET_malloc (sizeof (struct Slave));
1745 slave->host_id = delegated_host_id;
1746 slave_list_add (slave);
1747 if (1 != msg->is_subordinate)
1750 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1752 &slave_event_callback, slave);
1754 if (NULL != slave->controller)
1755 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1757 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1758 "Could not connect to delegated controller");
1759 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1762 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1763 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1764 GNUNET_SERVER_client_keep (client);
1765 lcc->client = client;
1767 slave->controller_proc =
1768 GNUNET_TESTBED_controller_start (master_context->master_ip,
1769 host_list[slave->host_id], cfg,
1770 &slave_status_callback, slave);
1771 GNUNET_CONFIGURATION_destroy (cfg);
1772 new_route = GNUNET_malloc (sizeof (struct Route));
1773 new_route->dest = delegated_host_id;
1774 new_route->thru = master_context->host_id;
1775 route_list_add (new_route);
1779 /* Route the request */
1780 if (slave_host_id >= route_list_size)
1782 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1783 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1786 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1787 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1788 lcfq->lcf->delegated_host_id = delegated_host_id;
1789 lcfq->lcf->slave_host_id = slave_host_id;
1790 route = find_dest_route (slave_host_id);
1791 GNUNET_assert (NULL != route); /* because we add routes carefully */
1792 GNUNET_assert (route->dest < slave_list_size);
1793 GNUNET_assert (NULL != slave_list[route->dest]);
1794 lcfq->lcf->state = INIT;
1795 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1796 lcfq->lcf->gateway = slave_list[route->dest];
1797 lcfq->lcf->msg = GNUNET_malloc (msize);
1798 (void) memcpy (lcfq->lcf->msg, msg, msize);
1799 GNUNET_SERVER_client_keep (client);
1800 lcfq->lcf->client = client;
1801 if (NULL == lcfq_head)
1803 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1804 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1805 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1808 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1809 /* FIXME: Adding a new route should happen after the controllers are linked
1811 if (1 != msg->is_subordinate)
1813 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1816 if ((delegated_host_id < route_list_size)
1817 && (NULL != route_list[delegated_host_id]))
1819 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1820 with is subordinate flag set to GNUNET_YES? */
1821 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1824 new_route = GNUNET_malloc (sizeof (struct Route));
1825 new_route->dest = delegated_host_id;
1826 new_route->thru = route->dest;
1827 route_list_add (new_route);
1828 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1833 * The task to be executed if the forwarded peer create operation has been
1836 * @param cls the FowardedOperationContext
1837 * @param tc the TaskContext from the scheduler
1840 peer_create_forward_timeout (void *cls,
1841 const struct GNUNET_SCHEDULER_TaskContext *tc)
1843 struct ForwardedOperationContext *fo_ctxt = cls;
1845 /* send error msg to client */
1846 GNUNET_free (fo_ctxt->cls);
1847 send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, "Timedout");
1848 GNUNET_SERVER_client_drop (fo_ctxt->client);
1849 GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc);
1850 GNUNET_free (fo_ctxt);
1855 * Callback to be called when forwarded peer create operation is
1856 * successfull. We have to relay the reply msg back to the client
1858 * @param cls ForwardedOperationContext
1859 * @param msg the peer create success message
1862 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1864 struct ForwardedOperationContext *fo_ctxt = cls;
1865 struct GNUNET_MessageHeader *dup_msg;
1866 struct Peer *remote_peer;
1869 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);
1870 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
1872 GNUNET_assert (NULL != fo_ctxt->cls);
1873 remote_peer = fo_ctxt->cls;
1874 peer_list_add (remote_peer);
1876 msize = ntohs (msg->size);
1877 dup_msg = GNUNET_malloc (msize);
1878 (void) memcpy (dup_msg, msg, msize);
1879 queue_message (fo_ctxt->client, dup_msg);
1880 GNUNET_SERVER_client_drop (fo_ctxt->client);
1881 GNUNET_free (fo_ctxt);
1887 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1890 * @param client identification of the client
1891 * @param message the actual message
1894 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1895 const struct GNUNET_MessageHeader *message)
1897 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1898 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1899 struct GNUNET_CONFIGURATION_Handle *cfg;
1900 struct ForwardedOperationContext *fo_ctxt;
1901 struct Route *route;
1906 uint32_t config_size;
1912 msize = ntohs (message->size);
1913 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1915 GNUNET_break (0); /* We need configuration */
1916 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1919 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1920 host_id = ntohl (msg->host_id);
1921 peer_id = ntohl (msg->peer_id);
1922 if (UINT32_MAX == peer_id)
1924 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1925 "Cannot create peer with given ID");
1926 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1929 if (host_id == master_context->host_id)
1933 /* We are responsible for this peer */
1934 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1935 config_size = ntohl (msg->config_size);
1936 config = GNUNET_malloc (config_size);
1937 dest_size = config_size;
1940 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1941 (const Bytef *) &msg[1], (uLong) msize)))
1943 GNUNET_break (0); /* uncompression error */
1944 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1947 if (config_size != dest_size)
1949 GNUNET_break (0); /* Uncompressed config size mismatch */
1950 GNUNET_free (config);
1951 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1954 cfg = GNUNET_CONFIGURATION_create ();
1956 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1958 GNUNET_break (0); /* Configuration parsing error */
1959 GNUNET_free (config);
1960 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1963 GNUNET_free (config);
1964 peer = GNUNET_malloc (sizeof (struct Peer));
1965 peer->is_remote = GNUNET_NO;
1966 peer->details.local.cfg = cfg;
1968 LOG_DEBUG ("Creating peer with id: %u\n", peer->id);
1969 peer->details.local.peer =
1970 GNUNET_TESTING_peer_configure (master_context->system,
1971 peer->details.local.cfg, peer->id,
1972 NULL /* Peer id */ ,
1974 if (NULL == peer->details.local.peer)
1976 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1980 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1983 peer->details.local.is_running = GNUNET_NO;
1984 peer_list_add (peer);
1986 GNUNET_malloc (sizeof
1987 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1988 reply->header.size =
1989 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1990 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
1991 reply->peer_id = msg->peer_id;
1992 reply->operation_id = msg->operation_id;
1993 queue_message (client, &reply->header);
1994 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1998 /* Forward peer create request */
1999 route = find_dest_route (host_id);
2003 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2007 peer = GNUNET_malloc (sizeof (struct Peer));
2008 peer->is_remote = GNUNET_YES;
2010 peer->details.remote.controller = slave_list[route->dest]->controller;
2011 peer->details.remote.remote_host_id = host_id;
2012 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2013 GNUNET_SERVER_client_keep (client);
2014 fo_ctxt->client = client;
2015 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
2016 fo_ctxt->cls = peer; //slave_list[route->dest]->controller;
2018 GNUNET_TESTBED_forward_operation_msg_ (slave_list [route->dest]->controller,
2019 fo_ctxt->operation_id,
2021 peer_create_success_cb, fo_ctxt);
2022 fo_ctxt->timeout_task =
2023 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
2025 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2030 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2033 * @param client identification of the client
2034 * @param message the actual message
2037 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
2038 const struct GNUNET_MessageHeader *message)
2040 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
2041 struct ForwardedOperationContext *fopc;
2045 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
2046 peer_id = ntohl (msg->peer_id);
2047 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
2048 peer_id, GNUNET_ntohll (msg->operation_id));
2049 if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id]))
2051 LOG (GNUNET_ERROR_TYPE_ERROR,
2052 "Asked to destroy a non existent peer with id: %u\n", peer_id);
2053 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2054 "Peer doesn't exist");
2055 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2058 peer = peer_list[peer_id];
2059 if (GNUNET_YES == peer->is_remote)
2061 /* Forward the destory message to sub controller */
2062 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2063 GNUNET_SERVER_client_keep (client);
2064 fopc->client = client;
2065 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2067 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2068 fopc->operation_id, &msg->header,
2069 &forwarded_operation_reply_relay,
2071 fopc->timeout_task =
2072 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2074 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2077 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
2078 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
2079 peer_list_remove (peer);
2081 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
2082 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2087 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2090 * @param client identification of the client
2091 * @param message the actual message
2094 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
2095 const struct GNUNET_MessageHeader *message)
2097 const struct GNUNET_TESTBED_PeerStartMessage *msg;
2098 struct GNUNET_TESTBED_PeerEventMessage *reply;
2099 struct ForwardedOperationContext *fopc;
2103 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
2104 peer_id = ntohl (msg->peer_id);
2105 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2108 LOG (GNUNET_ERROR_TYPE_ERROR,
2109 "Asked to start a non existent peer with id: %u\n", peer_id);
2110 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2113 peer = peer_list[peer_id];
2114 if (GNUNET_YES == peer->is_remote)
2116 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2117 GNUNET_SERVER_client_keep (client);
2118 fopc->client = client;
2119 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2121 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2122 fopc->operation_id, &msg->header,
2123 &forwarded_operation_reply_relay,
2125 fopc->timeout_task =
2126 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2128 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2131 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
2133 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2135 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2138 peer->details.local.is_running = GNUNET_YES;
2139 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2140 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
2141 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2142 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
2143 reply->host_id = htonl (master_context->host_id);
2144 reply->peer_id = msg->peer_id;
2145 reply->operation_id = msg->operation_id;
2146 queue_message (client, &reply->header);
2147 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2152 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2155 * @param client identification of the client
2156 * @param message the actual message
2159 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
2160 const struct GNUNET_MessageHeader *message)
2162 const struct GNUNET_TESTBED_PeerStopMessage *msg;
2163 struct GNUNET_TESTBED_PeerEventMessage *reply;
2164 struct ForwardedOperationContext *fopc;
2168 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
2169 peer_id = ntohl (msg->peer_id);
2170 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2172 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2174 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2177 peer = peer_list[peer_id];
2178 if (GNUNET_YES == peer->is_remote)
2180 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2181 GNUNET_SERVER_client_keep (client);
2182 fopc->client = client;
2183 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2185 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2186 fopc->operation_id, &msg->header,
2187 &forwarded_operation_reply_relay,
2189 fopc->timeout_task =
2190 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2192 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2195 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer->details.local.peer))
2197 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2198 "Peer not running");
2199 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2202 peer->details.local.is_running = GNUNET_NO;
2203 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2204 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
2205 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2206 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
2207 reply->host_id = htonl (master_context->host_id);
2208 reply->peer_id = msg->peer_id;
2209 reply->operation_id = msg->operation_id;
2210 queue_message (client, &reply->header);
2211 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2216 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
2219 * @param client identification of the client
2220 * @param message the actual message
2223 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
2224 const struct GNUNET_MessageHeader *message)
2226 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
2227 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
2236 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
2237 peer_id = ntohl (msg->peer_id);
2238 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2240 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2242 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2245 peer = peer_list[peer_id];
2246 if (GNUNET_YES == peer->is_remote)
2248 struct ForwardedOperationContext *fopc;
2250 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2251 GNUNET_SERVER_client_keep (client);
2252 fopc->client = client;
2253 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2255 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2256 fopc->operation_id, &msg->header,
2257 &forwarded_operation_reply_relay,
2259 fopc->timeout_task =
2260 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2262 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2266 GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->details.local.cfg,
2268 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
2269 GNUNET_free (config);
2272 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
2273 reply = GNUNET_realloc (xconfig, msize);
2274 (void) memmove (&reply[1], reply, xc_size);
2275 reply->header.size = htons (msize);
2276 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG);
2277 reply->peer_id = msg->peer_id;
2278 reply->operation_id = msg->operation_id;
2279 GNUNET_TESTING_peer_get_identity (peer_list[peer_id]->details.local.peer,
2280 &reply->peer_identity);
2281 reply->config_size = htons ((uint16_t) c_size);
2282 queue_message (client, &reply->header);
2283 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2288 * Task for cleaing up overlay connect context structure
2290 * @param cls the overlay connect context
2291 * @param tc the task context
2294 occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2296 struct OverlayConnectContext *occ = cls;
2298 LOG_DEBUG ("Cleaning up occ\n");
2299 GNUNET_free_non_null (occ->emsg);
2300 GNUNET_free_non_null (occ->hello);
2301 GNUNET_SERVER_client_drop (occ->client);
2302 if (NULL != occ->opc)
2303 GNUNET_TESTBED_forward_operation_msg_cancel_ (occ->opc);
2304 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2305 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2306 if (NULL != occ->ch)
2307 GNUNET_CORE_disconnect (occ->ch);
2308 if (NULL != occ->ghh)
2309 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2310 if (NULL != occ->p1th)
2311 GNUNET_TRANSPORT_disconnect (occ->p1th);
2312 if (NULL != occ->p2th)
2313 GNUNET_TRANSPORT_disconnect (occ->p2th);
2319 * Task which will be run when overlay connect request has been timed out
2321 * @param cls the OverlayConnectContext
2322 * @param tc the TaskContext
2325 timeout_overlay_connect (void *cls,
2326 const struct GNUNET_SCHEDULER_TaskContext *tc)
2328 struct OverlayConnectContext *occ = cls;
2330 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2331 send_operation_fail_msg (occ->client, occ->op_id, occ->emsg);
2332 occ_cleanup (occ, tc);
2338 * Function called to notify transport users that another
2339 * peer connected to us.
2341 * @param cls closure
2342 * @param new_peer the peer that connected
2343 * @param ats performance data
2344 * @param ats_count number of entries in ats (excluding 0-termination)
2347 overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2348 const struct GNUNET_ATS_Information *ats,
2349 unsigned int ats_count)
2351 struct OverlayConnectContext *occ = cls;
2352 struct GNUNET_TESTBED_ConnectionEventMessage *msg;
2354 char *other_peer_str;
2356 LOG_DEBUG ("Overlay connect notify\n");
2358 memcmp (new_peer, &occ->peer_identity,
2359 sizeof (struct GNUNET_PeerIdentity)))
2361 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer));
2362 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2364 memcmp (new_peer, &occ->other_peer_identity,
2365 sizeof (struct GNUNET_PeerIdentity)))
2367 LOG_DEBUG ("Unexpected peer %4s connected when expecting peer %4s\n",
2368 new_peer_str, other_peer_str);
2369 GNUNET_free (new_peer_str);
2370 GNUNET_free (other_peer_str);
2373 GNUNET_free (new_peer_str);
2374 LOG_DEBUG ("Peer %4s connected to peer %4s\n", other_peer_str,
2375 GNUNET_i2s (&occ->peer_identity));
2376 GNUNET_free (other_peer_str);
2377 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2379 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2380 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2382 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
2383 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2384 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2385 GNUNET_free_non_null (occ->emsg);
2387 if (NULL != occ->p2th)
2388 GNUNET_TRANSPORT_disconnect (occ->p2th);
2390 LOG_DEBUG ("Peers connected - Sending overlay connect success\n");
2391 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2393 htons (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2394 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT);
2395 msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
2396 msg->peer1 = htonl (occ->peer_id);
2397 msg->peer2 = htonl (occ->other_peer_id);
2398 msg->operation_id = GNUNET_htonll (occ->op_id);
2399 queue_message (occ->client, &msg->header);
2400 GNUNET_SCHEDULER_add_now (&occ_cleanup, occ);
2405 * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to
2408 * @param cls the OverlayConnectContext
2409 * @param tc the TaskContext from scheduler
2412 send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2414 struct OverlayConnectContext *occ = cls;
2415 char *other_peer_str;
2417 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2418 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2420 GNUNET_assert (NULL != occ->hello);
2421 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2422 if (NULL != occ->peer2_controller)
2424 struct GNUNET_TESTBED_RequestConnectMessage *msg;
2426 uint16_t hello_size;
2428 LOG_DEBUG ("Offering HELLO of %s to %s via Remote Overlay Request\n",
2429 GNUNET_i2s (&occ->peer_identity), other_peer_str);
2430 hello_size = ntohs (occ->hello->size);
2431 msize = sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hello_size;
2432 msg = GNUNET_malloc (msize);
2433 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT);
2434 msg->header.size = htons (msize);
2435 msg->peer = htonl (occ->other_peer_id);
2436 msg->operation_id = GNUNET_htonll (occ->op_id);
2437 (void) memcpy (&msg->peer_identity, &occ->peer_identity,
2438 sizeof (struct GNUNET_PeerIdentity));
2439 memcpy (msg->hello, occ->hello, hello_size);
2440 GNUNET_TESTBED_queue_message_ (occ->peer2_controller, &msg->header);
2444 LOG_DEBUG ("Offering HELLO of %s to %s\n",
2445 GNUNET_i2s (&occ->peer_identity), other_peer_str);
2446 GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL);
2447 GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity);
2448 occ->send_hello_task =
2449 GNUNET_SCHEDULER_add_delayed
2450 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
2451 100 * (pow (2, occ->retries++))),
2454 GNUNET_free (other_peer_str);
2458 * Test for checking whether HELLO message is empty
2460 * @param cls empty flag to set
2461 * @param address the HELLO
2462 * @param expiration expiration of the HELLO
2466 test_address (void *cls, const struct GNUNET_HELLO_Address *address,
2467 struct GNUNET_TIME_Absolute expiration)
2477 * Function called whenever there is an update to the HELLO of peers in the
2478 * OverlayConnectClosure. If we have a valid HELLO, we connect to the peer 2's
2479 * transport and offer peer 1's HELLO and ask peer 2 to connect to peer 1
2481 * @param cls closure
2482 * @param hello our updated HELLO
2485 hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2487 struct OverlayConnectContext *occ = cls;
2491 msize = ntohs (hello->size);
2493 (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *)
2494 hello, GNUNET_NO, &test_address,
2496 if (GNUNET_YES == empty)
2498 LOG_DEBUG ("HELLO of %s is empty\n", GNUNET_i2s (&occ->peer_identity));
2501 LOG_DEBUG ("Received HELLO of %s\n", GNUNET_i2s (&occ->peer_identity));
2502 occ->hello = GNUNET_malloc (msize);
2503 memcpy (occ->hello, hello, msize);
2504 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2506 GNUNET_TRANSPORT_disconnect (occ->p1th);
2508 GNUNET_free_non_null (occ->emsg);
2509 if (NULL == occ->peer2_controller)
2512 GNUNET_TRANSPORT_connect (peer_list[occ->other_peer_id]->details.local.cfg,
2513 &occ->other_peer_identity, NULL, NULL, NULL,
2515 if (NULL == occ->p2th)
2517 GNUNET_asprintf (&occ->emsg, "Cannot connect to TRANSPORT of %s\n",
2518 GNUNET_i2s (&occ->other_peer_identity));
2519 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2520 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2524 occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer");
2525 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
2530 * Function called after GNUNET_CORE_connect has succeeded (or failed
2531 * for good). Note that the private key of the peer is intentionally
2532 * not exposed here; if you need it, your process should try to read
2533 * the private key file directly (which should work if you are
2536 * @param cls closure
2537 * @param server handle to the server, NULL if we failed
2538 * @param my_identity ID of this peer, NULL if we failed
2541 core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
2542 const struct GNUNET_PeerIdentity *my_identity)
2544 struct OverlayConnectContext *occ = cls;
2546 GNUNET_free_non_null (occ->emsg);
2547 occ->emsg = GNUNET_strdup ("Failed to connect to CORE\n");
2548 if ((NULL == server) || (NULL == my_identity))
2550 GNUNET_free (occ->emsg);
2553 memcpy (&occ->peer_identity, my_identity,
2554 sizeof (struct GNUNET_PeerIdentity));
2556 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg,
2557 &occ->peer_identity, NULL, NULL, NULL, NULL);
2558 if (NULL == occ->p1th)
2560 GNUNET_asprintf (&occ->emsg, "Cannot connect to TRANSPORT of peers %4s",
2561 GNUNET_i2s (&occ->peer_identity));
2564 LOG_DEBUG ("Acquiring HELLO of peer %s\n", GNUNET_i2s (&occ->peer_identity));
2565 occ->emsg = GNUNET_strdup ("Timeout while acquiring HELLO message");
2566 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p1th, &hello_update_cb, occ);
2570 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2571 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2577 * Callback to be called when forwarded get peer config operation as part of
2578 * overlay connect is successfull. Connection to Peer 1's core is made and is
2579 * checked for new connection from peer 2
2581 * @param cls ForwardedOperationContext
2582 * @param msg the peer create success message
2585 overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg)
2587 struct OverlayConnectContext *occ = cls;
2588 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg;
2589 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2594 if (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG != ntohs (msg->type))
2596 cmsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
2598 memcpy (&occ->other_peer_identity, &cmsg->peer_identity,
2599 sizeof (struct GNUNET_PeerIdentity));
2600 GNUNET_free_non_null (occ->emsg);
2601 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2603 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2604 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2605 GNUNET_NO, no_handlers);
2606 if (NULL == occ->ch)
2611 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2613 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2618 * This callback is a part of overlay connect operation. This will be run when
2619 * the registration operation of peer2's controller is completed at peer1's
2622 * @param cls the ForwardedOverlayConnectContext
2623 * @param emsg the error message in case of any failure; NULL if host
2624 * registration is successfull.
2627 focc_reg_completion_cc (void *cls, const char *emsg)
2629 struct ForwardedOverlayConnectContext *focc = cls;
2630 struct GNUNET_CONFIGURATION_Handle *cfg;
2632 GNUNET_assert (FOCC_REGISTER == focc->state);
2633 focc->rhandle = NULL;
2634 GNUNET_assert (NULL == focc->sub_op);
2635 LOG_DEBUG ("Registering peer2's host successful\n");
2636 if ((NULL == focc->gateway2)
2637 || ((focc->peer2_host_id < slave_list_size) /* Check if we have the needed config */
2638 && (NULL != slave_list[focc->peer2_host_id])))
2640 focc->state = FOCC_LINK;
2641 cfg = (NULL == focc->gateway2) ?
2642 our_config : slave_list[focc->peer2_host_id]->cfg;
2644 GNUNET_TESTBED_controller_link_ (focc,
2646 focc->peer2_host_id,
2647 peer_list[focc->peer1]->details.remote.remote_host_id,
2652 focc->state = FOCC_GET_CFG;
2653 focc->sub_op = GNUNET_TESTBED_get_slave_config_ (focc, focc->gateway2,
2654 focc->peer2_host_id);
2659 * Callback to be called when forwarded overlay connection operation has a reply
2660 * from the sub-controller successfull. We have to relay the reply msg back to
2663 * @param cls ForwardedOperationContext
2664 * @param msg the peer create success message
2667 forwarded_overlay_connect_listener (void *cls,
2668 const struct GNUNET_MessageHeader *msg)
2670 struct ForwardedOperationContext *fopc = cls;
2671 struct ForwardedOverlayConnectContext *focc;
2676 forwarded_operation_reply_relay (cls, msg);
2679 switch (focc->state)
2682 if (GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG != ntohs (msg->type))
2684 GNUNET_break (0); /* Something failed; you may check output of
2686 cleanup_focc (focc);
2687 forwarded_operation_reply_relay (cls, msg);
2690 LOG_DEBUG ("Registering peer2's host\n");
2691 focc->state = FOCC_REGISTER;
2693 GNUNET_TESTBED_register_host (focc->gateway,
2694 host_list[focc->peer2_host_id],
2695 focc_reg_completion_cc, focc);
2700 GNUNET_SERVER_client_drop (fopc->client);
2701 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
2702 fopc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2708 * Timeout task for cancelling a forwarded overlay connect connect
2710 * @param cls the ForwardedOverlayConnectContext
2711 * @param tc the task context from the scheduler
2714 forwarded_overlay_connect_timeout (void *cls,
2715 const struct GNUNET_SCHEDULER_TaskContext
2718 struct ForwardedOverlayConnectContext *focc = cls;
2720 focc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2721 send_operation_fail_msg (focc->client, focc->operation_id, "Timeout");
2722 cleanup_focc (focc);
2727 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
2730 * @param client identification of the client
2731 * @param message the actual message
2734 handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
2735 const struct GNUNET_MessageHeader *message)
2737 const struct GNUNET_TESTBED_OverlayConnectMessage *msg;
2738 struct OverlayConnectContext *occ;
2739 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2743 uint64_t operation_id;
2746 uint32_t peer2_host_id;
2748 msg = (const struct GNUNET_TESTBED_OverlayConnectMessage *) message;
2749 p1 = ntohl (msg->peer1);
2750 p2 = ntohl (msg->peer2);
2751 peer2_host_id = ntohl (msg->peer2_host_id);
2752 GNUNET_assert (p1 < peer_list_size);
2753 GNUNET_assert (NULL != peer_list[p1]);
2754 peer = peer_list[p1];
2755 operation_id = GNUNET_ntohll (msg->operation_id);
2756 if (GNUNET_YES == peer->is_remote)
2758 struct ForwardedOperationContext *fopc;
2759 struct Route *route_to_peer2_host;
2760 struct Route *route_to_peer1_host;
2762 LOG_DEBUG ("Forwarding overlay connect\n");
2763 GNUNET_SERVER_client_keep (client);
2764 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2765 fopc->client = client;
2766 fopc->operation_id = operation_id;
2767 route_to_peer2_host = NULL;
2768 route_to_peer1_host = NULL;
2769 route_to_peer2_host = find_dest_route (peer2_host_id);
2770 if ((NULL != route_to_peer2_host)
2771 || (peer2_host_id == master_context->host_id))
2773 route_to_peer1_host =
2774 find_dest_route (peer_list[p1]->details.remote.remote_host_id);
2775 GNUNET_assert (NULL != route_to_peer1_host);
2776 if ((peer2_host_id == master_context->host_id)
2777 || (route_to_peer2_host->dest != route_to_peer1_host->dest))
2779 struct ForwardedOverlayConnectContext *focc;
2782 msize = sizeof (struct GNUNET_TESTBED_OverlayConnectMessage);
2783 focc = GNUNET_malloc (sizeof (struct ForwardedOverlayConnectContext));
2784 focc->gateway = peer->details.remote.controller;
2785 focc->gateway2 = (NULL == route_to_peer2_host) ? NULL :
2786 slave_list[route_to_peer2_host->dest]->controller;
2789 focc->peer2_host_id = peer2_host_id;
2790 focc->state = FOCC_INIT;
2791 focc->orig_msg = GNUNET_malloc (msize);
2792 (void) memcpy (focc->orig_msg, message, msize);
2793 GNUNET_SERVER_client_keep (client);
2794 focc->client = client;
2795 focc->operation_id = operation_id;
2797 fopc->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
2798 &forwarded_overlay_connect_timeout,
2803 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2804 operation_id, message,
2805 &forwarded_overlay_connect_listener,
2807 fopc->timeout_task =
2808 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2810 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2813 occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
2814 GNUNET_SERVER_client_keep (client);
2815 occ->client = client;
2817 occ->other_peer_id = p2;
2818 occ->peer = peer_list[p1];
2819 occ->op_id = GNUNET_ntohll (msg->operation_id);
2820 if ((p2 >= peer_list_size) || (NULL == peer_list[p2]))
2822 if ((peer2_host_id >= slave_list_size)
2823 || (NULL ==slave_list[peer2_host_id]))
2825 struct GNUNET_TESTBED_NeedControllerConfig *reply;
2828 reply = GNUNET_malloc (sizeof (struct
2829 GNUNET_TESTBED_NeedControllerConfig));
2830 reply->header.size = htons (sizeof (struct
2831 GNUNET_TESTBED_NeedControllerConfig));
2832 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG);
2833 reply->controller_host_id = msg->peer2_host_id;
2834 reply->operation_id = msg->operation_id;
2835 queue_message (client, &reply->header);
2836 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2841 occ->peer2_controller = slave_list[peer2_host_id]->controller;
2842 if (NULL == occ->peer2_controller)
2844 GNUNET_break (0); /* What's going on? */
2845 GNUNET_SERVER_client_drop (client);
2847 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2854 if (GNUNET_YES == peer_list[occ->other_peer_id]->is_remote)
2855 occ->peer2_controller = peer_list[occ->other_peer_id]->details.remote.controller;
2857 /* Get the identity of the second peer */
2858 if (NULL != occ->peer2_controller)
2860 struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg;
2863 htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
2864 cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG);
2865 cmsg.peer_id = msg->peer2;
2866 cmsg.operation_id = msg->operation_id;
2868 GNUNET_TESTBED_forward_operation_msg_ (occ->peer2_controller,
2869 occ->op_id, &cmsg.header,
2870 &overlay_connect_get_config,
2873 GNUNET_strdup ("Timeout while getting peer identity of peer B\n");
2875 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2876 (GNUNET_TIME_UNIT_SECONDS, 30),
2877 &timeout_overlay_connect, occ);
2878 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2881 GNUNET_TESTING_peer_get_identity (peer_list[occ->other_peer_id]->details.local.peer,
2882 &occ->other_peer_identity);
2883 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */
2884 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2886 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2887 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2888 GNUNET_NO, no_handlers);
2889 if (NULL == occ->ch)
2891 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2894 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2895 (GNUNET_TIME_UNIT_SECONDS, 30),
2896 &timeout_overlay_connect, occ);
2897 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2902 * Function to cleanup RequestOverlayConnectContext and any associated tasks
2905 * @param rocc the RequestOverlayConnectContext
2908 cleanup_rocc (struct RequestOverlayConnectContext *rocc)
2910 if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id)
2911 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
2912 if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id)
2913 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id);
2914 GNUNET_TRANSPORT_disconnect (rocc->th);
2915 GNUNET_free_non_null (rocc->hello);
2921 * Task to timeout rocc and cleanit up
2923 * @param cls the RequestOverlayConnectContext
2924 * @param tc the TaskContext from scheduler
2927 timeout_rocc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2929 struct RequestOverlayConnectContext *rocc = cls;
2931 rocc->timeout_rocc_task_id = GNUNET_SCHEDULER_NO_TASK;
2932 cleanup_rocc (rocc);
2937 * Function called to notify transport users that another
2938 * peer connected to us.
2940 * @param cls closure
2941 * @param new_peer the peer that connected
2942 * @param ats performance data
2943 * @param ats_count number of entries in ats (excluding 0-termination)
2946 transport_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2947 const struct GNUNET_ATS_Information * ats,
2950 struct RequestOverlayConnectContext *rocc = cls;
2952 LOG_DEBUG ("Request Overlay connect notify\n");
2953 if (0 != memcmp (new_peer, &rocc->a_id, sizeof (struct GNUNET_PeerIdentity)))
2955 LOG_DEBUG ("Peer %4s connected\n", GNUNET_i2s (&rocc->a_id));
2956 cleanup_rocc (rocc);
2961 * Task to offer the HELLO message to the peer and ask it to connect to the peer
2962 * whose identity is in RequestOverlayConnectContext
2964 * @param cls the RequestOverlayConnectContext
2965 * @param tc the TaskContext from scheduler
2968 attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2970 struct RequestOverlayConnectContext *rocc = cls;
2972 rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK;
2973 GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, NULL, NULL);
2974 GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id);
2975 rocc->attempt_connect_task_id =
2976 GNUNET_SCHEDULER_add_delayed
2977 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
2978 100 * (pow (2, rocc->retries++))),
2979 &attempt_connect_task, rocc);
2984 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages
2987 * @param client identification of the client
2988 * @param message the actual message
2991 handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
2992 const struct GNUNET_MessageHeader *message)
2994 const struct GNUNET_TESTBED_RequestConnectMessage *msg;
2995 struct RequestOverlayConnectContext *rocc;
3001 msize = ntohs (message->size);
3002 if (sizeof (struct GNUNET_TESTBED_RequestConnectMessage) >= msize)
3005 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3008 msg = (const struct GNUNET_TESTBED_RequestConnectMessage *) message;
3009 if ((NULL == msg->hello) ||
3010 (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type)))
3013 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3016 hsize = ntohs (msg->hello->size);
3017 if ((sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hsize) != msize)
3020 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3023 peer_id = ntohl (msg->peer);
3024 if ((peer_id >= peer_list_size) || (NULL == (peer = peer_list[peer_id])))
3026 GNUNET_break_op (0);
3027 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3030 if (GNUNET_YES == peer->is_remote)
3032 struct GNUNET_MessageHeader *msg2;
3034 msg2 = GNUNET_malloc (msize);
3035 (void) memcpy (msg2, message, msize);
3036 GNUNET_TESTBED_queue_message_ (peer->details.remote.controller, msg2);
3037 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3040 rocc = GNUNET_malloc (sizeof (struct RequestOverlayConnectContext));
3041 rocc->th = GNUNET_TRANSPORT_connect (peer->details.local.cfg, NULL, rocc,
3042 NULL, &transport_connect_notify, NULL);
3043 if (NULL == rocc->th)
3047 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3050 memcpy (&rocc->a_id, &msg->peer_identity,
3051 sizeof (struct GNUNET_PeerIdentity));
3052 rocc->hello = GNUNET_malloc (hsize);
3053 memcpy (rocc->hello, msg->hello, hsize);
3054 rocc->attempt_connect_task_id =
3055 GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
3056 rocc->timeout_rocc_task_id =
3057 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc);
3058 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3063 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
3066 * @param client identification of the client
3067 * @param message the actual message
3070 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
3071 const struct GNUNET_MessageHeader *message)
3073 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
3074 struct Slave *slave;
3075 struct GNUNET_TESTBED_SlaveConfiguration *reply;
3079 size_t xconfig_size;
3084 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
3085 slave_id = ntohl (msg->slave_id);
3086 op_id = GNUNET_ntohll (msg->operation_id);
3087 if ((slave_list_size <= slave_id) || (NULL == slave_list[slave_id]))
3089 send_operation_fail_msg (client, op_id, "Slave not found");
3090 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3093 slave = slave_list[slave_id];
3094 if (NULL == slave->cfg)
3096 send_operation_fail_msg (client, op_id,
3097 "Configuration not found (slave not started by me)");
3098 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3101 config = GNUNET_CONFIGURATION_serialize (slave->cfg, &config_size);
3102 xconfig_size = GNUNET_TESTBED_compress_config_ (config, config_size,
3104 GNUNET_free (config);
3105 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
3106 GNUNET_break (reply_size <= UINT16_MAX);
3107 GNUNET_break (config_size <= UINT16_MAX);
3108 reply = GNUNET_realloc (xconfig, reply_size);
3109 (void) memmove (&reply[1], reply, xconfig_size);
3110 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG);
3111 reply->header.size = htons ((uint16_t) reply_size);
3112 reply->slave_id = msg->slave_id;
3113 reply->operation_id = msg->operation_id;
3114 reply->config_size = htons ((uint16_t) config_size);
3115 queue_message (client, &reply->header);
3116 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3121 * Iterator over hash map entries.
3123 * @param cls closure
3124 * @param key current key code
3125 * @param value value in the hash map
3126 * @return GNUNET_YES if we should continue to
3131 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
3133 struct SharedService *ss = value;
3135 GNUNET_assert (GNUNET_YES ==
3136 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
3137 GNUNET_free (ss->name);
3144 * Task to clean up and shutdown nicely
3147 * @param tc the TaskContext from scheduler
3150 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3152 struct LCFContextQueue *lcfq;
3155 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
3156 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
3157 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
3159 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
3160 if (NULL != lcfq_head)
3162 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
3164 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
3165 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
3167 if (NULL != lcfq_head->lcf->rhandle)
3168 GNUNET_TESTBED_cancel_registration (lcfq_head->lcf->rhandle);
3170 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
3171 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
3173 GNUNET_free (lcfq->lcf->msg);
3174 GNUNET_free (lcfq->lcf);
3175 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
3178 /* Clear peer list */
3179 for (id = 0; id < peer_list_size; id++)
3180 if (NULL != peer_list[id])
3182 if (GNUNET_NO == peer_list[id]->is_remote)
3184 if (GNUNET_YES == peer_list[id]->details.local.is_running)
3185 GNUNET_TESTING_peer_stop (peer_list[id]->details.local.peer);
3186 GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
3187 GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
3189 GNUNET_free (peer_list[id]);
3191 GNUNET_free_non_null (peer_list);
3192 /* Clear host list */
3193 for (id = 0; id < host_list_size; id++)
3194 if (NULL != host_list[id])
3195 GNUNET_TESTBED_host_destroy (host_list[id]);
3196 GNUNET_free_non_null (host_list);
3197 /* Clear route list */
3198 for (id = 0; id < route_list_size; id++)
3199 if (NULL != route_list[id])
3200 GNUNET_free (route_list[id]);
3201 GNUNET_free_non_null (route_list);
3202 /* Clear slave_list */
3203 for (id = 0; id < slave_list_size; id++)
3204 if (NULL != slave_list[id])
3206 if (NULL != slave_list[id]->cfg)
3207 GNUNET_CONFIGURATION_destroy (slave_list[id]->cfg);
3208 if (NULL != slave_list[id]->controller)
3209 GNUNET_TESTBED_controller_disconnect (slave_list[id]->controller);
3210 if (NULL != slave_list[id]->controller_proc)
3211 GNUNET_TESTBED_controller_stop (slave_list[id]->controller_proc);
3212 GNUNET_free (slave_list[id]);
3214 GNUNET_free_non_null (slave_list);
3215 if (NULL != master_context)
3217 GNUNET_free_non_null (master_context->master_ip);
3218 if (NULL != master_context->system)
3219 GNUNET_TESTING_system_destroy (master_context->system, GNUNET_YES);
3220 GNUNET_free (master_context);
3221 master_context = NULL;
3223 GNUNET_free_non_null (hostname);
3224 GNUNET_CONFIGURATION_destroy (our_config);
3229 * Callback for client disconnect
3232 * @param client the client which has disconnected
3235 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
3237 if (NULL == master_context)
3239 if (client == master_context->client)
3241 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
3242 GNUNET_SERVER_client_drop (client);
3243 /* should not be needed as we're terminated by failure to read
3244 * from stdin, but if stdin fails for some reason, this shouldn't
3245 * hurt for now --- might need to revise this later if we ever
3246 * decide that master connections might be temporarily down
3247 * for some reason */
3248 //GNUNET_SCHEDULER_shutdown ();
3256 * @param cls closure
3257 * @param server the initialized server
3258 * @param cfg configuration to use
3261 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
3262 const struct GNUNET_CONFIGURATION_Handle *cfg)
3264 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
3265 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
3266 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
3267 {&handle_configure_shared_service, NULL,
3268 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
3269 {&handle_link_controllers, NULL,
3270 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
3271 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
3272 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER,
3273 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
3274 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER,
3275 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
3276 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER,
3277 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
3278 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG,
3279 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
3280 {&handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT,
3281 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
3282 {&handle_overlay_request_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT,
3284 {handle_slave_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG,
3285 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
3289 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
3290 (cfg, "testbed", "HOSTNAME", &hostname));
3291 our_config = GNUNET_CONFIGURATION_dup (cfg);
3292 GNUNET_SERVER_add_handlers (server, message_handlers);
3293 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
3294 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
3296 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
3297 &shutdown_task, NULL);
3298 LOG_DEBUG ("Testbed startup complete\n");
3299 event_mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
3304 * The starting point of execution
3307 main (int argc, char *const *argv)
3309 //sleep (15); /* Debugging */
3310 return (GNUNET_OK ==
3311 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
3312 &testbed_run, NULL)) ? 0 : 1;
3315 /* end of gnunet-service-testbed.c */