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 id of the operation which created this context information
574 uint64_t operation_id;
577 * Enumeration of states for this context
587 * State where we attempt to get peer2's controller configuration
592 * State where we attempt to link the controller of peer 1 to the controller
598 * State where we attempt to do the overlay connection again
615 * Id of the host where peer2 is running
617 uint32_t peer2_host_id;
623 * The master context; generated with the first INIT message
625 static struct Context *master_context;
628 * Our hostname; we give this to all the peers we start
630 static char *hostname;
637 * Current Transmit Handle; NULL if no notify transmit exists currently
639 static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
646 * The head for the LCF queue
648 static struct LCFContextQueue *lcfq_head;
651 * The tail for the LCF queue
653 static struct LCFContextQueue *lcfq_tail;
656 * The message queue head
658 static struct MessageQueue *mq_head;
661 * The message queue tail
663 static struct MessageQueue *mq_tail;
668 static struct GNUNET_TESTBED_Host **host_list;
673 static struct Route **route_list;
676 * A list of directly linked neighbours
678 static struct Slave **slave_list;
681 * A list of peers we know about
683 static struct Peer **peer_list;
686 * The hashmap of shared services
688 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
691 * The event mask for the events we listen from sub-controllers
693 static uint64_t event_mask;
696 * The size of the host list
698 static uint32_t host_list_size;
701 * The size of the route list
703 static uint32_t route_list_size;
706 * The size of directly linked neighbours list
708 static uint32_t slave_list_size;
711 * The size of the peer list
713 static uint32_t peer_list_size;
720 * The lcf_task handle
722 static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
725 * The shutdown task handle
727 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
731 * Function called to notify a client about the connection begin ready to queue
732 * more data. "buf" will be NULL and "size" zero if the connection was closed
733 * for writing in the meantime.
736 * @param size number of bytes available in buf
737 * @param buf where the callee should write the message
738 * @return number of bytes written to buf
741 transmit_ready_notify (void *cls, size_t size, void *buf)
743 struct MessageQueue *mq_entry;
745 transmit_handle = NULL;
747 GNUNET_assert (NULL != mq_entry);
750 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
751 size = ntohs (mq_entry->msg->size);
752 memcpy (buf, mq_entry->msg, size);
753 GNUNET_free (mq_entry->msg);
754 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
755 GNUNET_free (mq_entry);
757 if (NULL != mq_entry)
759 GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
760 ntohs (mq_entry->msg->size),
761 GNUNET_TIME_UNIT_FOREVER_REL,
762 &transmit_ready_notify, NULL);
768 * Queues a message in send queue for sending to the service
770 * @param client the client to whom the queued message has to be sent
771 * @param msg the message to queue
774 queue_message (struct GNUNET_SERVER_Client *client,
775 struct GNUNET_MessageHeader *msg)
777 struct MessageQueue *mq_entry;
781 type = ntohs (msg->type);
782 size = ntohs (msg->size);
783 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
784 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
785 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
787 mq_entry->client = client;
788 LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type,
790 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
791 if (NULL == transmit_handle)
793 GNUNET_SERVER_notify_transmit_ready (client, size,
794 GNUNET_TIME_UNIT_FOREVER_REL,
795 &transmit_ready_notify, NULL);
800 * Similar to GNUNET_realloc; however clears tail part of newly allocated memory
802 * @param ptr the memory block to realloc
803 * @param size the size of ptr
804 * @param new_size the size to which ptr has to be realloc'ed
805 * @return the newly reallocated memory block
808 TESTBED_realloc (void *ptr, size_t size, size_t new_size)
810 ptr = GNUNET_realloc (ptr, new_size);
812 (void) memset (ptr + size, 0, new_size - size);
818 * Function to add a host to the current list of known hosts
820 * @param host the host to add
821 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
825 host_list_add (struct GNUNET_TESTBED_Host *host)
830 host_id = GNUNET_TESTBED_host_get_id_ (host);
831 orig_size = host_list_size;
832 if (host_list_size <= host_id)
834 while (host_list_size <= host_id)
835 host_list_size += LIST_GROW_STEP;
837 TESTBED_realloc (host_list,
838 sizeof (struct GNUNET_TESTBED_Host *) * orig_size,
839 sizeof (struct GNUNET_TESTBED_Host *)
842 if (NULL != host_list[host_id])
844 LOG_DEBUG ("A host with id: %u already exists\n", host_id);
845 return GNUNET_SYSERR;
847 host_list[host_id] = host;
853 * Adds a route to the route list
855 * @param route the route to add
858 route_list_add (struct Route *route)
862 orig_size = route_list_size;
863 if (route->dest >= route_list_size)
865 while (route->dest >= route_list_size)
866 route_list_size += LIST_GROW_STEP;
868 TESTBED_realloc (route_list,
869 sizeof (struct Route *) * orig_size,
870 sizeof (struct Route *) * route_list_size);
872 GNUNET_assert (NULL == route_list[route->dest]);
873 route_list[route->dest] = route;
878 * Adds a slave to the slave array
880 * @param slave the slave controller to add
883 slave_list_add (struct Slave *slave)
885 if (slave->host_id >= slave_list_size)
888 TESTBED_realloc (slave_list, sizeof (struct Slave *) * slave_list_size,
889 sizeof (struct Slave *) * (slave_list_size +
891 slave_list_size += LIST_GROW_STEP;
893 GNUNET_assert (NULL == slave_list[slave->host_id]);
894 slave_list[slave->host_id] = slave;
899 * Adds a peer to the peer array
901 * @param peer the peer to add
904 peer_list_add (struct Peer *peer)
908 orig_size = peer_list_size;
909 if (peer->id >= peer_list_size)
911 while (peer->id >= peer_list_size)
912 peer_list_size += LIST_GROW_STEP;
914 TESTBED_realloc (peer_list, sizeof (struct Peer *) * orig_size,
915 sizeof (struct Peer *) * peer_list_size);
917 GNUNET_assert (NULL == peer_list[peer->id]);
918 peer_list[peer->id] = peer;
923 * Removes a the give peer from the peer array
925 * @param peer the peer to be removed
928 peer_list_remove (struct Peer *peer)
933 peer_list[peer->id] = NULL;
934 orig_size = peer_list_size;
935 while (peer_list_size >= LIST_GROW_STEP)
937 for (id = peer_list_size - 1;
938 (id >= peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); id--)
939 if (NULL != peer_list[id])
941 if (id != ((peer_list_size - LIST_GROW_STEP) - 1))
943 peer_list_size -= LIST_GROW_STEP;
945 if (orig_size == peer_list_size)
948 GNUNET_realloc (peer_list, sizeof (struct Peer *) * peer_list_size);
953 * Finds the route with directly connected host as destination through which
954 * the destination host can be reached
956 * @param host_id the id of the destination host
957 * @return the route with directly connected destination host; NULL if no route
960 static struct Route *
961 find_dest_route (uint32_t host_id)
965 if (route_list_size <= host_id)
967 while (NULL != (route = route_list[host_id]))
969 if (route->thru == master_context->host_id)
971 host_id = route->thru;
978 * Routes message to a host given its host_id
980 * @param host_id the id of the destination host
981 * @param msg the message to be routed
984 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
991 * Send operation failure message to client
993 * @param client the client to which the failure message has to be sent to
994 * @param operation_id the id of the failed operation
995 * @param emsg the error message; can be NULL
998 send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
999 uint64_t operation_id, const char *emsg)
1001 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
1005 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
1006 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
1008 msg = GNUNET_malloc (msize);
1009 msg->header.size = htons (msize);
1010 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONFAILEVENT);
1011 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
1012 msg->operation_id = GNUNET_htonll (operation_id);
1014 memcpy (&msg[1], emsg, emsg_len);
1015 queue_message (client, &msg->header);
1020 * Function to send generic operation success message to given client
1022 * @param client the client to send the message to
1023 * @param operation_id the id of the operation which was successful
1026 send_operation_success_msg (struct GNUNET_SERVER_Client *client,
1027 uint64_t operation_id)
1029 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
1032 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
1033 msg = GNUNET_malloc (msize);
1034 msg->header.size = htons (msize);
1035 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
1036 msg->operation_id = GNUNET_htonll (operation_id);
1037 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
1038 queue_message (client, &msg->header);
1043 * The Link Controller forwarding task
1045 * @param cls the LCFContext
1046 * @param tc the Task context from scheduler
1049 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1053 * Completion callback for host registrations while forwarding Link Controller messages
1055 * @param cls the LCFContext
1056 * @param emsg the error message; NULL if host registration is successful
1059 lcf_proc_cc (void *cls, const char *emsg)
1061 struct LCFContext *lcf = cls;
1063 lcf->rhandle = NULL;
1064 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1069 goto registration_error;
1070 lcf->state = DELEGATED_HOST_REGISTERED;
1071 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1073 case DELEGATED_HOST_REGISTERED:
1075 goto registration_error;
1076 lcf->state = SLAVE_HOST_REGISTERED;
1077 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1080 GNUNET_assert (0); /* Shouldn't reach here */
1085 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
1087 lcf->state = FINISHED;
1088 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1093 * Callback to be called when forwarded link controllers operation is
1094 * successfull. We have to relay the reply msg back to the client
1096 * @param cls ForwardedOperationContext
1097 * @param msg the peer create success message
1100 forwarded_operation_reply_relay (void *cls,
1101 const struct GNUNET_MessageHeader *msg)
1103 struct ForwardedOperationContext *fopc = cls;
1104 struct GNUNET_MessageHeader *dup_msg;
1107 msize = ntohs (msg->size);
1108 LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type),
1110 dup_msg = GNUNET_malloc (msize);
1111 (void) memcpy (dup_msg, msg, msize);
1112 queue_message (fopc->client, dup_msg);
1113 GNUNET_SERVER_client_drop (fopc->client);
1114 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
1120 * Task to free resources when forwarded link controllers has been timedout
1122 * @param cls the ForwardedOperationContext
1123 * @param tc the task context from scheduler
1126 forwarded_operation_timeout (void *cls,
1127 const struct GNUNET_SCHEDULER_TaskContext *tc)
1129 struct ForwardedOperationContext *fopc = cls;
1131 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
1132 send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
1133 GNUNET_SERVER_client_drop (fopc->client);
1139 * The Link Controller forwarding task
1141 * @param cls the LCFContext
1142 * @param tc the Task context from scheduler
1145 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1147 struct LCFContext *lcf = cls;
1148 struct LCFContextQueue *lcfq;
1149 struct ForwardedOperationContext *fopc;
1151 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
1156 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id],
1157 lcf->gateway->controller))
1160 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1161 host_list[lcf->delegated_host_id],
1166 lcf->state = DELEGATED_HOST_REGISTERED;
1167 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1170 case DELEGATED_HOST_REGISTERED:
1172 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id],
1173 lcf->gateway->controller))
1176 GNUNET_TESTBED_register_host (lcf->gateway->controller,
1177 host_list[lcf->slave_host_id],
1182 lcf->state = SLAVE_HOST_REGISTERED;
1183 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1186 case SLAVE_HOST_REGISTERED:
1187 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1188 fopc->client = lcf->client;
1189 fopc->operation_id = lcf->operation_id;
1191 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
1194 &forwarded_operation_reply_relay,
1196 fopc->timeout_task =
1197 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1199 lcf->state = FINISHED;
1200 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
1204 GNUNET_assert (lcfq->lcf == lcf);
1205 GNUNET_free (lcf->msg);
1207 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
1209 if (NULL != lcfq_head)
1211 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
1217 * Callback to be called when forwarded overlay connection operation has a reply
1218 * from the sub-controller successfull. We have to relay the reply msg back to
1221 * @param cls ForwardedOperationContext
1222 * @param msg the peer create success message
1225 forwarded_overlay_connect_listener (void *cls,
1226 const struct GNUNET_MessageHeader *msg);
1230 * Cleans up ForwardedOverlayConnectContext
1232 * @param focc the ForwardedOverlayConnectContext to cleanup
1235 cleanup_focc (struct ForwardedOverlayConnectContext *focc)
1237 if (NULL != focc->sub_op)
1238 GNUNET_TESTBED_operation_done (focc->sub_op);
1239 GNUNET_SERVER_client_drop (focc->client);
1240 GNUNET_free_non_null (focc->orig_msg);
1245 * Callback for event from slave controllers
1247 * @param cls struct Slave *
1248 * @param event information about the event
1251 slave_event_callback (void *cls,
1252 const struct GNUNET_TESTBED_EventInformation *event)
1254 struct ForwardedOverlayConnectContext *focc;
1255 struct ForwardedOperationContext *fopc;
1256 struct GNUNET_CONFIGURATION_Handle *slave_cfg;
1257 struct GNUNET_TESTBED_Operation *old_op;
1260 /* We currently only get here when doing overlay connect operations and that
1261 too while trying out sub operations */
1262 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type);
1263 focc = event->details.operation_finished.op_cls;
1264 if (NULL != event->details.operation_finished.emsg)
1266 GNUNET_asprintf (&emsg, "Failure executing suboperation: %s",
1267 event->details.operation_finished.emsg);
1268 send_operation_fail_msg (focc->client, focc->operation_id,
1271 cleanup_focc (focc);
1274 switch (focc->state)
1277 slave_cfg = event->details.operation_finished.generic;
1278 old_op = focc->sub_op;
1279 focc->state = FOCC_LINK;
1280 focc->sub_op = GNUNET_TESTBED_controller_link_ (focc,
1282 focc->peer2_host_id,
1283 peer_list[focc->peer1]->details.remote.remote_host_id,
1286 GNUNET_TESTBED_operation_done (old_op);
1289 GNUNET_TESTBED_operation_done (focc->sub_op);
1290 focc->sub_op = NULL;
1291 focc->state = FOCC_OL_CONNECT;
1292 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1293 fopc->client = focc->client;
1294 focc->client = NULL;
1295 fopc->operation_id = focc->operation_id;
1298 GNUNET_TESTBED_forward_operation_msg_ (focc->gateway,
1299 focc->operation_id, focc->orig_msg,
1300 &forwarded_operation_reply_relay,
1302 GNUNET_free (focc->orig_msg);
1303 focc->orig_msg = NULL;
1304 fopc->timeout_task =
1305 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1307 cleanup_focc (focc);
1317 * Callback to signal successfull startup of the controller process
1319 * @param cls the handle to the slave whose status is to be found here
1320 * @param cfg the configuration with which the controller has been started;
1321 * NULL if status is not GNUNET_OK
1322 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
1323 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1326 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
1329 struct Slave *slave = cls;
1330 struct LinkControllersContext *lcc;
1333 if (GNUNET_SYSERR == status)
1335 slave->controller_proc = NULL;
1336 slave_list[slave->host_id] = NULL;
1337 if (NULL != slave->cfg)
1338 GNUNET_CONFIGURATION_destroy (slave->cfg);
1339 GNUNET_free (slave);
1341 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
1342 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
1346 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1348 &slave_event_callback, slave);
1349 if (NULL != slave->controller)
1351 send_operation_success_msg (lcc->client, lcc->operation_id);
1352 slave->cfg = GNUNET_CONFIGURATION_dup (cfg);
1356 send_operation_fail_msg (lcc->client, lcc->operation_id,
1357 "Could not connect to delegated controller");
1358 GNUNET_TESTBED_controller_stop (slave->controller_proc);
1359 slave_list[slave->host_id] = NULL;
1360 GNUNET_free (slave);
1367 if (NULL != lcc->client)
1369 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
1370 GNUNET_SERVER_client_drop (lcc->client);
1381 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
1384 * @param client identification of the client
1385 * @param message the actual message
1388 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
1389 const struct GNUNET_MessageHeader *message)
1391 const struct GNUNET_TESTBED_InitMessage *msg;
1392 struct GNUNET_TESTBED_Host *host;
1393 const char *controller_hostname;
1396 if (NULL != master_context)
1398 LOG_DEBUG ("We are being connected to laterally\n");
1399 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1402 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
1403 msize = ntohs (message->size);
1404 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
1407 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1410 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
1411 controller_hostname = (const char *) &msg[1];
1412 if ('\0' != controller_hostname[msize - 1])
1415 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1418 master_context = GNUNET_malloc (sizeof (struct Context));
1419 master_context->client = client;
1420 master_context->host_id = ntohl (msg->host_id);
1421 master_context->master_ip = GNUNET_strdup (controller_hostname);
1422 LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip);
1423 master_context->system =
1424 GNUNET_TESTING_system_create ("testbed", master_context->master_ip, hostname);
1426 GNUNET_TESTBED_host_create_with_id (master_context->host_id, NULL, NULL,
1428 host_list_add (host);
1429 GNUNET_SERVER_client_keep (client);
1430 LOG_DEBUG ("Created master context with host ID: %u\n",
1431 master_context->host_id);
1432 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1437 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1440 * @param client identification of the client
1441 * @param message the actual message
1444 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
1445 const struct GNUNET_MessageHeader *message)
1447 struct GNUNET_TESTBED_Host *host;
1448 const struct GNUNET_TESTBED_AddHostMessage *msg;
1449 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
1454 uint16_t username_length;
1455 uint16_t hostname_length;
1456 uint16_t reply_size;
1459 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
1460 msize = ntohs (msg->header.size);
1461 username = (char *) &(msg[1]);
1462 username_length = ntohs (msg->user_name_length);
1463 GNUNET_assert (msize > (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length + 1)); /* msg must contain hostname */
1464 if (0 != username_length)
1465 GNUNET_assert ('\0' == username[username_length]);
1466 username_length = (0 == username_length) ? 0 : username_length + 1;
1467 hostname = username + username_length;
1469 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
1470 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
1471 GNUNET_assert (strlen (hostname) == hostname_length - 1);
1472 host_id = ntohl (msg->host_id);
1473 LOG_DEBUG ("Received ADDHOST message\n");
1474 LOG_DEBUG ("-------host id: %u\n", host_id);
1475 LOG_DEBUG ("-------hostname: %s\n", hostname);
1476 if (0 != username_length)
1477 LOG_DEBUG ("-------username: %s\n", username);
1480 LOG_DEBUG ("-------username: NULL\n");
1483 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1485 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1486 ntohs (msg->ssh_port));
1487 GNUNET_assert (NULL != host);
1488 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1489 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1490 if (GNUNET_OK != host_list_add (host))
1492 /* We are unable to add a host */
1493 emsg = "A host exists with given host-id";
1494 LOG_DEBUG ("%s: %u", emsg, host_id);
1495 GNUNET_TESTBED_host_destroy (host);
1496 reply_size += strlen (emsg) + 1;
1497 reply = GNUNET_malloc (reply_size);
1498 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1501 reply = GNUNET_malloc (reply_size);
1502 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
1503 reply->header.size = htons (reply_size);
1504 reply->host_id = htonl (host_id);
1505 queue_message (client, &reply->header);
1510 * Iterator over hash map entries.
1512 * @param cls closure
1513 * @param key current key code
1514 * @param value value in the hash map
1515 * @return GNUNET_YES if we should continue to
1520 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1522 struct SharedService *queried_ss = cls;
1523 struct SharedService *ss = value;
1525 if (0 == strcmp (ss->name, queried_ss->name))
1533 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1536 * @param client identification of the client
1537 * @param message the actual message
1540 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1541 const struct GNUNET_MessageHeader *message)
1543 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1544 struct SharedService *ss;
1546 struct GNUNET_HashCode hash;
1548 uint16_t service_name_size;
1550 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1551 msg_size = ntohs (message->size);
1552 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1555 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1559 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1560 service_name = (char *) &msg[1];
1561 if ('\0' != service_name[service_name_size - 1])
1564 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1567 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1568 service_name, ntohl (msg->num_peers));
1569 if (ntohl (msg->host_id) != master_context->host_id)
1571 route_message (ntohl (msg->host_id), message);
1572 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1575 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1576 ss = GNUNET_malloc (sizeof (struct SharedService));
1577 ss->name = strdup (service_name);
1578 ss->num_shared = ntohl (msg->num_peers);
1579 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1580 if (GNUNET_SYSERR ==
1581 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1582 &ss_exists_iterator, ss))
1584 LOG (GNUNET_ERROR_TYPE_WARNING,
1585 "Service %s already configured as a shared service. "
1586 "Ignoring service sharing request \n", ss->name);
1587 GNUNET_free (ss->name);
1591 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1592 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1597 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1600 * @param client identification of the client
1601 * @param message the actual message
1604 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1605 const struct GNUNET_MessageHeader *message)
1607 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1608 struct GNUNET_CONFIGURATION_Handle *cfg;
1609 struct LCFContextQueue *lcfq;
1610 struct Route *route;
1611 struct Route *new_route;
1615 uint32_t delegated_host_id;
1616 uint32_t slave_host_id;
1619 if (NULL == master_context)
1622 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1625 msize = ntohs (message->size);
1626 if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
1629 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1632 msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
1633 delegated_host_id = ntohl (msg->delegated_host_id);
1634 if (delegated_host_id == master_context->host_id)
1637 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1638 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1641 if ((delegated_host_id >= host_list_size) ||
1642 (NULL == host_list[delegated_host_id]))
1644 LOG (GNUNET_ERROR_TYPE_WARNING,
1645 "Delegated host %u not registered with us\n", delegated_host_id);
1646 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1649 slave_host_id = ntohl (msg->slave_host_id);
1650 if ((slave_host_id >= host_list_size) || (NULL == host_list[slave_host_id]))
1652 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host not registered with us\n");
1653 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1656 if (slave_host_id == delegated_host_id)
1658 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1659 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1663 if (slave_host_id == master_context->host_id) /* Link from us */
1665 struct Slave *slave;
1666 struct LinkControllersContext *lcc;
1668 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1669 config_size = ntohs (msg->config_size);
1670 if ((delegated_host_id < slave_list_size) && (NULL != slave_list[delegated_host_id])) /* We have already added */
1672 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1674 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1677 config = GNUNET_malloc (config_size);
1678 dest_size = (uLongf) config_size;
1680 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1683 GNUNET_break (0); /* Compression error */
1684 GNUNET_free (config);
1685 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1688 if (config_size != dest_size)
1690 LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1691 GNUNET_free (config);
1692 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1695 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1697 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1699 GNUNET_break (0); /* Configuration parsing error */
1700 GNUNET_free (config);
1701 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1704 GNUNET_free (config);
1705 if ((delegated_host_id < slave_list_size) &&
1706 (NULL != slave_list[delegated_host_id]))
1708 GNUNET_break (0); /* Configuration parsing error */
1709 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1712 slave = GNUNET_malloc (sizeof (struct Slave));
1713 slave->host_id = delegated_host_id;
1714 slave_list_add (slave);
1715 if (1 != msg->is_subordinate)
1718 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1720 &slave_event_callback, slave);
1722 if (NULL != slave->controller)
1723 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1725 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1726 "Could not connect to delegated controller");
1727 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1730 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1731 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1732 GNUNET_SERVER_client_keep (client);
1733 lcc->client = client;
1735 slave->controller_proc =
1736 GNUNET_TESTBED_controller_start (master_context->master_ip,
1737 host_list[slave->host_id], cfg,
1738 &slave_status_callback, slave);
1739 GNUNET_CONFIGURATION_destroy (cfg);
1740 new_route = GNUNET_malloc (sizeof (struct Route));
1741 new_route->dest = delegated_host_id;
1742 new_route->thru = master_context->host_id;
1743 route_list_add (new_route);
1747 /* Route the request */
1748 if (slave_host_id >= route_list_size)
1750 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1751 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1754 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1755 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1756 lcfq->lcf->delegated_host_id = delegated_host_id;
1757 lcfq->lcf->slave_host_id = slave_host_id;
1758 route = find_dest_route (slave_host_id);
1759 GNUNET_assert (NULL != route); /* because we add routes carefully */
1760 GNUNET_assert (route->dest < slave_list_size);
1761 GNUNET_assert (NULL != slave_list[route->dest]);
1762 lcfq->lcf->state = INIT;
1763 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1764 lcfq->lcf->gateway = slave_list[route->dest];
1765 lcfq->lcf->msg = GNUNET_malloc (msize);
1766 (void) memcpy (lcfq->lcf->msg, msg, msize);
1767 GNUNET_SERVER_client_keep (client);
1768 lcfq->lcf->client = client;
1769 if (NULL == lcfq_head)
1771 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1772 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1773 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1776 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1777 /* FIXME: Adding a new route should happen after the controllers are linked
1779 if (1 != msg->is_subordinate)
1781 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1784 if ((delegated_host_id < route_list_size)
1785 && (NULL != route_list[delegated_host_id]))
1787 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1788 with is subordinate flag set to GNUNET_YES? */
1789 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1792 new_route = GNUNET_malloc (sizeof (struct Route));
1793 new_route->dest = delegated_host_id;
1794 new_route->thru = route->dest;
1795 route_list_add (new_route);
1796 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1801 * The task to be executed if the forwarded peer create operation has been
1804 * @param cls the FowardedOperationContext
1805 * @param tc the TaskContext from the scheduler
1808 peer_create_forward_timeout (void *cls,
1809 const struct GNUNET_SCHEDULER_TaskContext *tc)
1811 struct ForwardedOperationContext *fo_ctxt = cls;
1813 /* send error msg to client */
1814 GNUNET_free (fo_ctxt->cls);
1815 send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, "Timedout");
1816 GNUNET_SERVER_client_drop (fo_ctxt->client);
1817 GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc);
1818 GNUNET_free (fo_ctxt);
1823 * Callback to be called when forwarded peer create operation is
1824 * successfull. We have to relay the reply msg back to the client
1826 * @param cls ForwardedOperationContext
1827 * @param msg the peer create success message
1830 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1832 struct ForwardedOperationContext *fo_ctxt = cls;
1833 const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *success_msg;
1834 struct GNUNET_MessageHeader *dup_msg;
1835 struct Peer *remote_peer;
1838 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);
1839 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
1842 (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *) msg;
1843 GNUNET_assert (NULL != fo_ctxt->cls);
1844 remote_peer = fo_ctxt->cls;
1845 GNUNET_assert (remote_peer->details.remote.remote_host_id
1846 == ntohl (success_msg->peer_id));
1847 peer_list_add (remote_peer);
1849 msize = ntohs (msg->size);
1850 dup_msg = GNUNET_malloc (msize);
1851 (void) memcpy (dup_msg, msg, msize);
1852 queue_message (fo_ctxt->client, dup_msg);
1853 GNUNET_SERVER_client_drop (fo_ctxt->client);
1854 GNUNET_free (fo_ctxt);
1860 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1863 * @param client identification of the client
1864 * @param message the actual message
1867 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1868 const struct GNUNET_MessageHeader *message)
1870 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1871 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1872 struct GNUNET_CONFIGURATION_Handle *cfg;
1873 struct ForwardedOperationContext *fo_ctxt;
1874 struct Route *route;
1879 uint32_t config_size;
1885 msize = ntohs (message->size);
1886 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1888 GNUNET_break (0); /* We need configuration */
1889 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1892 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1893 host_id = ntohl (msg->host_id);
1894 peer_id = ntohl (msg->peer_id);
1895 if (UINT32_MAX == peer_id)
1897 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1898 "Cannot create peer with given ID");
1899 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1902 if (host_id == master_context->host_id)
1906 /* We are responsible for this peer */
1907 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1908 config_size = ntohl (msg->config_size);
1909 config = GNUNET_malloc (config_size);
1910 dest_size = config_size;
1913 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1914 (const Bytef *) &msg[1], (uLong) msize)))
1916 GNUNET_break (0); /* uncompression error */
1917 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1920 if (config_size != dest_size)
1922 GNUNET_break (0); /* Uncompressed config size mismatch */
1923 GNUNET_free (config);
1924 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1927 cfg = GNUNET_CONFIGURATION_create ();
1929 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1931 GNUNET_break (0); /* Configuration parsing error */
1932 GNUNET_free (config);
1933 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1936 GNUNET_free (config);
1937 peer = GNUNET_malloc (sizeof (struct Peer));
1938 peer->is_remote = GNUNET_NO;
1939 peer->details.local.cfg = cfg;
1941 LOG_DEBUG ("Creating peer with id: %u\n", peer->id);
1942 peer->details.local.peer =
1943 GNUNET_TESTING_peer_configure (master_context->system,
1944 peer->details.local.cfg, peer->id,
1945 NULL /* Peer id */ ,
1947 if (NULL == peer->details.local.peer)
1949 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1953 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1956 peer->details.local.is_running = GNUNET_NO;
1957 peer_list_add (peer);
1959 GNUNET_malloc (sizeof
1960 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1961 reply->header.size =
1962 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1963 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
1964 reply->peer_id = msg->peer_id;
1965 reply->operation_id = msg->operation_id;
1966 queue_message (client, &reply->header);
1967 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1971 /* Forward peer create request */
1972 route = find_dest_route (host_id);
1976 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1980 peer = GNUNET_malloc (sizeof (struct Peer));
1981 peer->is_remote = GNUNET_YES;
1983 peer->details.remote.controller = slave_list[route->dest]->controller;
1984 peer->details.remote.remote_host_id = host_id;
1985 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1986 GNUNET_SERVER_client_keep (client);
1987 fo_ctxt->client = client;
1988 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1989 fo_ctxt->cls = peer; //slave_list[route->dest]->controller;
1991 GNUNET_TESTBED_forward_operation_msg_ (slave_list [route->dest]->controller,
1992 fo_ctxt->operation_id,
1994 peer_create_success_cb, fo_ctxt);
1995 fo_ctxt->timeout_task =
1996 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
1998 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2003 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2006 * @param client identification of the client
2007 * @param message the actual message
2010 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
2011 const struct GNUNET_MessageHeader *message)
2013 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
2014 struct ForwardedOperationContext *fopc;
2018 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
2019 peer_id = ntohl (msg->peer_id);
2020 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
2021 peer_id, GNUNET_ntohll (msg->operation_id));
2022 if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id]))
2024 LOG (GNUNET_ERROR_TYPE_ERROR,
2025 "Asked to destroy a non existent peer with id: %u\n", peer_id);
2026 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2027 "Peer doesn't exist");
2028 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2031 peer = peer_list[peer_id];
2032 if (GNUNET_YES == peer->is_remote)
2034 /* Forward the destory message to sub controller */
2035 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2036 GNUNET_SERVER_client_keep (client);
2037 fopc->client = client;
2038 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2040 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2041 fopc->operation_id, &msg->header,
2042 &forwarded_operation_reply_relay,
2044 fopc->timeout_task =
2045 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2047 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2050 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
2051 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
2052 peer_list_remove (peer);
2054 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
2055 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2060 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2063 * @param client identification of the client
2064 * @param message the actual message
2067 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
2068 const struct GNUNET_MessageHeader *message)
2070 const struct GNUNET_TESTBED_PeerStartMessage *msg;
2071 struct GNUNET_TESTBED_PeerEventMessage *reply;
2072 struct ForwardedOperationContext *fopc;
2076 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
2077 peer_id = ntohl (msg->peer_id);
2078 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2081 LOG (GNUNET_ERROR_TYPE_ERROR,
2082 "Asked to start a non existent peer with id: %u\n", peer_id);
2083 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2086 peer = peer_list[peer_id];
2087 if (GNUNET_YES == peer->is_remote)
2089 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2090 GNUNET_SERVER_client_keep (client);
2091 fopc->client = client;
2092 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2094 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2095 fopc->operation_id, &msg->header,
2096 &forwarded_operation_reply_relay,
2098 fopc->timeout_task =
2099 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2101 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2104 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
2106 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2108 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2111 peer->details.local.is_running = GNUNET_YES;
2112 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2113 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
2114 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2115 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
2116 reply->host_id = htonl (master_context->host_id);
2117 reply->peer_id = msg->peer_id;
2118 reply->operation_id = msg->operation_id;
2119 queue_message (client, &reply->header);
2120 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2125 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
2128 * @param client identification of the client
2129 * @param message the actual message
2132 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
2133 const struct GNUNET_MessageHeader *message)
2135 const struct GNUNET_TESTBED_PeerStopMessage *msg;
2136 struct GNUNET_TESTBED_PeerEventMessage *reply;
2137 struct ForwardedOperationContext *fopc;
2141 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
2142 peer_id = ntohl (msg->peer_id);
2143 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2145 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2147 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2150 peer = peer_list[peer_id];
2151 if (GNUNET_YES == peer->is_remote)
2153 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2154 GNUNET_SERVER_client_keep (client);
2155 fopc->client = client;
2156 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2158 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2159 fopc->operation_id, &msg->header,
2160 &forwarded_operation_reply_relay,
2162 fopc->timeout_task =
2163 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2165 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2168 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer->details.local.peer))
2170 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2171 "Peer not running");
2172 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2175 peer->details.local.is_running = GNUNET_NO;
2176 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2177 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
2178 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2179 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
2180 reply->host_id = htonl (master_context->host_id);
2181 reply->peer_id = msg->peer_id;
2182 reply->operation_id = msg->operation_id;
2183 queue_message (client, &reply->header);
2184 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2189 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
2192 * @param client identification of the client
2193 * @param message the actual message
2196 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
2197 const struct GNUNET_MessageHeader *message)
2199 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
2200 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
2209 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
2210 peer_id = ntohl (msg->peer_id);
2211 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2213 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2215 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2218 peer = peer_list[peer_id];
2219 if (GNUNET_YES == peer->is_remote)
2221 struct ForwardedOperationContext *fopc;
2223 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2224 GNUNET_SERVER_client_keep (client);
2225 fopc->client = client;
2226 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2228 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2229 fopc->operation_id, &msg->header,
2230 &forwarded_operation_reply_relay,
2232 fopc->timeout_task =
2233 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2235 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2239 GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->details.local.cfg,
2241 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
2242 GNUNET_free (config);
2245 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
2246 reply = GNUNET_realloc (xconfig, msize);
2247 (void) memmove (&reply[1], reply, xc_size);
2248 reply->header.size = htons (msize);
2249 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG);
2250 reply->peer_id = msg->peer_id;
2251 reply->operation_id = msg->operation_id;
2252 GNUNET_TESTING_peer_get_identity (peer_list[peer_id]->details.local.peer,
2253 &reply->peer_identity);
2254 reply->config_size = htons ((uint16_t) c_size);
2255 queue_message (client, &reply->header);
2256 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2261 * Task for cleaing up overlay connect context structure
2263 * @param cls the overlay connect context
2264 * @param tc the task context
2267 occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2269 struct OverlayConnectContext *occ = cls;
2271 LOG_DEBUG ("Cleaning up occ\n");
2272 GNUNET_free_non_null (occ->emsg);
2273 GNUNET_free_non_null (occ->hello);
2274 GNUNET_SERVER_client_drop (occ->client);
2275 if (NULL != occ->opc)
2276 GNUNET_TESTBED_forward_operation_msg_cancel_ (occ->opc);
2277 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2278 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2279 if (NULL != occ->ch)
2280 GNUNET_CORE_disconnect (occ->ch);
2281 if (NULL != occ->ghh)
2282 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2283 if (NULL != occ->p1th)
2284 GNUNET_TRANSPORT_disconnect (occ->p1th);
2285 if (NULL != occ->p2th)
2286 GNUNET_TRANSPORT_disconnect (occ->p2th);
2292 * Task which will be run when overlay connect request has been timed out
2294 * @param cls the OverlayConnectContext
2295 * @param tc the TaskContext
2298 timeout_overlay_connect (void *cls,
2299 const struct GNUNET_SCHEDULER_TaskContext *tc)
2301 struct OverlayConnectContext *occ = cls;
2303 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2304 send_operation_fail_msg (occ->client, occ->op_id, occ->emsg);
2305 occ_cleanup (occ, tc);
2311 * Function called to notify transport users that another
2312 * peer connected to us.
2314 * @param cls closure
2315 * @param new_peer the peer that connected
2316 * @param ats performance data
2317 * @param ats_count number of entries in ats (excluding 0-termination)
2320 overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2321 const struct GNUNET_ATS_Information *ats,
2322 unsigned int ats_count)
2324 struct OverlayConnectContext *occ = cls;
2325 struct GNUNET_TESTBED_ConnectionEventMessage *msg;
2327 char *other_peer_str;
2329 LOG_DEBUG ("Overlay connect notify\n");
2331 memcmp (new_peer, &occ->peer_identity,
2332 sizeof (struct GNUNET_PeerIdentity)))
2334 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer));
2335 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2337 memcmp (new_peer, &occ->other_peer_identity,
2338 sizeof (struct GNUNET_PeerIdentity)))
2340 LOG_DEBUG ("Unexpected peer %4s connected when expecting peer %4s\n",
2341 new_peer_str, other_peer_str);
2342 GNUNET_free (new_peer_str);
2343 GNUNET_free (other_peer_str);
2346 GNUNET_free (new_peer_str);
2347 LOG_DEBUG ("Peer %4s connected to peer %4s\n", other_peer_str,
2348 GNUNET_i2s (&occ->peer_identity));
2349 GNUNET_free (other_peer_str);
2350 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2352 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2353 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2355 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
2356 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2357 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2358 GNUNET_free_non_null (occ->emsg);
2360 if (NULL != occ->p2th)
2361 GNUNET_TRANSPORT_disconnect (occ->p2th);
2363 LOG_DEBUG ("Peers connected - Sending overlay connect success\n");
2364 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2366 htons (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2367 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT);
2368 msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
2369 msg->peer1 = htonl (occ->peer_id);
2370 msg->peer2 = htonl (occ->other_peer_id);
2371 msg->operation_id = GNUNET_htonll (occ->op_id);
2372 queue_message (occ->client, &msg->header);
2373 GNUNET_SCHEDULER_add_now (&occ_cleanup, occ);
2378 * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to
2381 * @param cls the OverlayConnectContext
2382 * @param tc the TaskContext from scheduler
2385 send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2387 struct OverlayConnectContext *occ = cls;
2388 char *other_peer_str;
2390 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2391 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2393 GNUNET_assert (NULL != occ->hello);
2394 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2395 if (NULL != occ->peer2_controller)
2397 struct GNUNET_TESTBED_RequestConnectMessage *msg;
2399 uint16_t hello_size;
2401 LOG_DEBUG ("Offering HELLO of %s to %s via Remote Overlay Request\n",
2402 GNUNET_i2s (&occ->peer_identity), other_peer_str);
2403 hello_size = ntohs (occ->hello->size);
2404 msize = sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hello_size;
2405 msg = GNUNET_malloc (msize);
2406 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT);
2407 msg->header.size = htons (msize);
2408 msg->peer = htonl (occ->other_peer_id);
2409 msg->operation_id = GNUNET_htonll (occ->op_id);
2410 (void) memcpy (&msg->peer_identity, &occ->peer_identity,
2411 sizeof (struct GNUNET_PeerIdentity));
2412 memcpy (msg->hello, occ->hello, hello_size);
2413 GNUNET_TESTBED_queue_message_ (occ->peer2_controller, &msg->header);
2417 LOG_DEBUG ("Offering HELLO of %s to %s\n",
2418 GNUNET_i2s (&occ->peer_identity), other_peer_str);
2419 GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL);
2420 GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity);
2421 occ->send_hello_task =
2422 GNUNET_SCHEDULER_add_delayed
2423 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
2424 100 * (pow (2, occ->retries++))),
2427 GNUNET_free (other_peer_str);
2431 * Test for checking whether HELLO message is empty
2433 * @param cls empty flag to set
2434 * @param address the HELLO
2435 * @param expiration expiration of the HELLO
2439 test_address (void *cls, const struct GNUNET_HELLO_Address *address,
2440 struct GNUNET_TIME_Absolute expiration)
2450 * Function called whenever there is an update to the HELLO of peers in the
2451 * OverlayConnectClosure. If we have a valid HELLO, we connect to the peer 2's
2452 * transport and offer peer 1's HELLO and ask peer 2 to connect to peer 1
2454 * @param cls closure
2455 * @param hello our updated HELLO
2458 hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2460 struct OverlayConnectContext *occ = cls;
2464 msize = ntohs (hello->size);
2466 (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *)
2467 hello, GNUNET_NO, &test_address,
2469 if (GNUNET_YES == empty)
2471 LOG_DEBUG ("HELLO of %s is empty\n", GNUNET_i2s (&occ->peer_identity));
2474 LOG_DEBUG ("Received HELLO of %s\n", GNUNET_i2s (&occ->peer_identity));
2475 occ->hello = GNUNET_malloc (msize);
2476 memcpy (occ->hello, hello, msize);
2477 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2479 GNUNET_TRANSPORT_disconnect (occ->p1th);
2481 GNUNET_free_non_null (occ->emsg);
2482 if (NULL == occ->peer2_controller)
2485 GNUNET_TRANSPORT_connect (peer_list[occ->other_peer_id]->details.local.cfg,
2486 &occ->other_peer_identity, NULL, NULL, NULL,
2488 if (NULL == occ->p2th)
2490 GNUNET_asprintf (&occ->emsg, "Cannot connect to TRANSPORT of %s\n",
2491 GNUNET_i2s (&occ->other_peer_identity));
2492 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2493 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2497 occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer");
2498 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
2503 * Function called after GNUNET_CORE_connect has succeeded (or failed
2504 * for good). Note that the private key of the peer is intentionally
2505 * not exposed here; if you need it, your process should try to read
2506 * the private key file directly (which should work if you are
2509 * @param cls closure
2510 * @param server handle to the server, NULL if we failed
2511 * @param my_identity ID of this peer, NULL if we failed
2514 core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
2515 const struct GNUNET_PeerIdentity *my_identity)
2517 struct OverlayConnectContext *occ = cls;
2519 GNUNET_free_non_null (occ->emsg);
2520 occ->emsg = GNUNET_strdup ("Failed to connect to CORE\n");
2521 if ((NULL == server) || (NULL == my_identity))
2523 GNUNET_free (occ->emsg);
2526 memcpy (&occ->peer_identity, my_identity,
2527 sizeof (struct GNUNET_PeerIdentity));
2529 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg,
2530 &occ->peer_identity, NULL, NULL, NULL, NULL);
2531 if (NULL == occ->p1th)
2533 GNUNET_asprintf (&occ->emsg, "Cannot connect to TRANSPORT of peers %4s",
2534 GNUNET_i2s (&occ->peer_identity));
2537 LOG_DEBUG ("Acquiring HELLO of peer %s\n", GNUNET_i2s (&occ->peer_identity));
2538 occ->emsg = GNUNET_strdup ("Timeout while acquiring HELLO message");
2539 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p1th, &hello_update_cb, occ);
2543 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2544 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2550 * Callback to be called when forwarded get peer config operation as part of
2551 * overlay connect is successfull. Connection to Peer 1's core is made and is
2552 * checked for new connection from peer 2
2554 * @param cls ForwardedOperationContext
2555 * @param msg the peer create success message
2558 overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg)
2560 struct OverlayConnectContext *occ = cls;
2561 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg;
2562 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2567 if (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG != ntohs (msg->type))
2569 cmsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
2571 memcpy (&occ->other_peer_identity, &cmsg->peer_identity,
2572 sizeof (struct GNUNET_PeerIdentity));
2573 GNUNET_free_non_null (occ->emsg);
2574 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2576 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2577 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2578 GNUNET_NO, no_handlers);
2579 if (NULL == occ->ch)
2584 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2586 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2591 * Callback to be called when forwarded overlay connection operation has a reply
2592 * from the sub-controller successfull. We have to relay the reply msg back to
2595 * @param cls ForwardedOperationContext
2596 * @param msg the peer create success message
2599 forwarded_overlay_connect_listener (void *cls,
2600 const struct GNUNET_MessageHeader *msg)
2602 struct ForwardedOperationContext *fopc = cls;
2603 struct ForwardedOverlayConnectContext *focc;
2608 forwarded_operation_reply_relay (cls, msg);
2611 switch (focc->state)
2614 if (GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG != ntohs (msg->type))
2616 GNUNET_break (0); /* Something failed; you may check output of
2618 cleanup_focc (focc);
2619 forwarded_operation_reply_relay (cls, msg);
2622 GNUNET_assert (NULL == focc->sub_op);
2623 focc->state = FOCC_GET_CFG;
2624 focc->sub_op = GNUNET_TESTBED_get_slave_config_ (focc, focc->gateway2,
2625 focc->peer2_host_id);
2630 GNUNET_SERVER_client_drop (fopc->client);
2631 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
2632 fopc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2638 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
2641 * @param client identification of the client
2642 * @param message the actual message
2645 handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
2646 const struct GNUNET_MessageHeader *message)
2648 const struct GNUNET_TESTBED_OverlayConnectMessage *msg;
2649 struct OverlayConnectContext *occ;
2650 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2654 uint64_t operation_id;
2657 uint32_t peer2_host_id;
2660 msg = (const struct GNUNET_TESTBED_OverlayConnectMessage *) message;
2661 p1 = ntohl (msg->peer1);
2662 p2 = ntohl (msg->peer2);
2663 peer2_host_id = ntohl (msg->peer2_host_id);
2664 GNUNET_assert (p1 < peer_list_size);
2665 GNUNET_assert (NULL != peer_list[p1]);
2666 peer = peer_list[p1];
2667 operation_id = GNUNET_ntohll (msg->operation_id);
2668 if (GNUNET_YES == peer->is_remote)
2670 struct ForwardedOperationContext *fopc;
2671 struct Route *route_to_peer2_host;
2672 struct Route *route_to_peer1_host;
2674 LOG_DEBUG ("Forwarding overlay connect\n");
2675 GNUNET_SERVER_client_keep (client);
2676 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2677 fopc->client = client;
2678 fopc->operation_id = operation_id;
2679 route_to_peer2_host = NULL;
2680 route_to_peer1_host = NULL;
2681 route_to_peer2_host = find_dest_route (peer2_host_id);
2682 if (NULL != route_to_peer2_host)
2684 route_to_peer1_host =
2685 find_dest_route (peer_list[p1]->details.remote.remote_host_id);
2686 GNUNET_assert (NULL != route_to_peer1_host);
2687 if (route_to_peer2_host->dest != route_to_peer1_host->dest)
2689 struct ForwardedOverlayConnectContext *focc;
2692 msize = sizeof (struct GNUNET_TESTBED_OverlayConnectMessage);
2693 focc = GNUNET_malloc (sizeof (struct ForwardedOverlayConnectContext));
2694 focc->gateway = peer->details.remote.controller;
2695 focc->gateway2 = slave_list[route_to_peer2_host->dest]->controller;
2698 focc->peer2_host_id = peer2_host_id;
2699 focc->state = FOCC_INIT;
2700 focc->orig_msg = GNUNET_malloc (msize);
2701 (void) memcpy (focc->orig_msg, message, msize);
2702 GNUNET_SERVER_client_keep (client);
2703 focc->client = client;
2704 focc->operation_id = operation_id;
2709 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
2710 operation_id, message,
2711 &forwarded_overlay_connect_listener,
2713 fopc->timeout_task =
2714 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2716 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2719 occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
2720 GNUNET_SERVER_client_keep (client);
2721 occ->client = client;
2723 occ->other_peer_id = p2;
2724 occ->peer = peer_list[p1];
2725 occ->op_id = GNUNET_ntohll (msg->operation_id);
2726 if ((p2 >= peer_list_size) || (NULL == peer_list[p2]))
2728 if ((peer2_host_id >= slave_list_size)
2729 || (NULL ==slave_list[peer2_host_id]))
2731 struct GNUNET_TESTBED_NeedControllerConfig *reply;
2734 reply = GNUNET_malloc (sizeof (struct
2735 GNUNET_TESTBED_NeedControllerConfig));
2736 reply->header.size = htons (sizeof (struct
2737 GNUNET_TESTBED_NeedControllerConfig));
2738 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG);
2739 reply->controller_host_id = msg->peer2_host_id;
2740 reply->operation_id = msg->operation_id;
2741 queue_message (client, &reply->header);
2742 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2747 occ->peer2_controller = slave_list[peer2_host_id]->controller;
2748 if (NULL == occ->peer2_controller)
2750 GNUNET_break (0); /* What's going on? */
2751 GNUNET_SERVER_client_drop (client);
2753 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2760 if (GNUNET_YES == peer_list[occ->other_peer_id]->is_remote)
2761 occ->peer2_controller = peer_list[occ->other_peer_id]->details.remote.controller;
2763 /* Get the identity of the second peer */
2764 if (NULL != occ->peer2_controller)
2766 struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg;
2769 htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
2770 cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG);
2771 cmsg.peer_id = msg->peer2;
2772 cmsg.operation_id = msg->operation_id;
2774 GNUNET_TESTBED_forward_operation_msg_ (occ->peer2_controller,
2775 occ->op_id, &cmsg.header,
2776 &overlay_connect_get_config,
2779 GNUNET_strdup ("Timeout while getting peer identity of peer B\n");
2781 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2782 (GNUNET_TIME_UNIT_SECONDS, 30),
2783 &timeout_overlay_connect, occ);
2784 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2787 GNUNET_TESTING_peer_get_identity (peer_list[occ->other_peer_id]->details.local.peer,
2788 &occ->other_peer_identity);
2789 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */
2790 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2792 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2793 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2794 GNUNET_NO, no_handlers);
2795 if (NULL == occ->ch)
2797 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2800 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2801 (GNUNET_TIME_UNIT_SECONDS, 30),
2802 &timeout_overlay_connect, occ);
2803 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2808 * Function to cleanup RequestOverlayConnectContext and any associated tasks
2811 * @param rocc the RequestOverlayConnectContext
2814 cleanup_rocc (struct RequestOverlayConnectContext *rocc)
2816 if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id)
2817 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
2818 if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id)
2819 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id);
2820 GNUNET_TRANSPORT_disconnect (rocc->th);
2821 GNUNET_free_non_null (rocc->hello);
2827 * Task to timeout rocc and cleanit up
2829 * @param cls the RequestOverlayConnectContext
2830 * @param tc the TaskContext from scheduler
2833 timeout_rocc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2835 struct RequestOverlayConnectContext *rocc = cls;
2837 rocc->timeout_rocc_task_id = GNUNET_SCHEDULER_NO_TASK;
2838 cleanup_rocc (rocc);
2843 * Function called to notify transport users that another
2844 * peer connected to us.
2846 * @param cls closure
2847 * @param new_peer the peer that connected
2848 * @param ats performance data
2849 * @param ats_count number of entries in ats (excluding 0-termination)
2852 transport_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2853 const struct GNUNET_ATS_Information * ats,
2856 struct RequestOverlayConnectContext *rocc = cls;
2858 LOG_DEBUG ("Request Overlay connect notify\n");
2859 if (0 != memcmp (new_peer, &rocc->a_id, sizeof (struct GNUNET_PeerIdentity)))
2861 LOG_DEBUG ("Peer %4s connected\n", GNUNET_i2s (&rocc->a_id));
2862 cleanup_rocc (rocc);
2867 * Task to offer the HELLO message to the peer and ask it to connect to the peer
2868 * whose identity is in RequestOverlayConnectContext
2870 * @param cls the RequestOverlayConnectContext
2871 * @param tc the TaskContext from scheduler
2874 attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2876 struct RequestOverlayConnectContext *rocc = cls;
2878 rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK;
2879 GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, NULL, NULL);
2880 GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id);
2881 rocc->attempt_connect_task_id =
2882 GNUNET_SCHEDULER_add_delayed
2883 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
2884 100 * (pow (2, rocc->retries++))),
2885 &attempt_connect_task, rocc);
2890 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages
2893 * @param client identification of the client
2894 * @param message the actual message
2897 handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
2898 const struct GNUNET_MessageHeader *message)
2900 const struct GNUNET_TESTBED_RequestConnectMessage *msg;
2901 struct RequestOverlayConnectContext *rocc;
2907 msize = ntohs (message->size);
2908 if (sizeof (struct GNUNET_TESTBED_RequestConnectMessage) >= msize)
2911 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2914 msg = (const struct GNUNET_TESTBED_RequestConnectMessage *) message;
2915 if ((NULL == msg->hello) ||
2916 (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type)))
2919 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2922 hsize = ntohs (msg->hello->size);
2923 if ((sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hsize) != msize)
2926 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2929 peer_id = ntohl (msg->peer);
2930 if ((peer_id >= peer_list_size) || (NULL == (peer = peer_list[peer_id])))
2932 GNUNET_break_op (0);
2933 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2936 if (GNUNET_YES == peer->is_remote)
2938 struct GNUNET_MessageHeader *msg2;
2940 msg2 = GNUNET_malloc (msize);
2941 (void) memcpy (msg2, message, msize);
2942 GNUNET_TESTBED_queue_message_ (peer->details.remote.controller, msg2);
2943 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2946 rocc = GNUNET_malloc (sizeof (struct RequestOverlayConnectContext));
2947 rocc->th = GNUNET_TRANSPORT_connect (peer->details.local.cfg, NULL, rocc,
2948 NULL, &transport_connect_notify, NULL);
2949 if (NULL == rocc->th)
2953 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2956 memcpy (&rocc->a_id, &msg->peer_identity,
2957 sizeof (struct GNUNET_PeerIdentity));
2958 rocc->hello = GNUNET_malloc (hsize);
2959 memcpy (rocc->hello, msg->hello, hsize);
2960 rocc->attempt_connect_task_id =
2961 GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
2962 rocc->timeout_rocc_task_id =
2963 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc);
2964 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2969 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
2972 * @param client identification of the client
2973 * @param message the actual message
2976 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
2977 const struct GNUNET_MessageHeader *message)
2979 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
2980 struct Slave *slave;
2981 struct GNUNET_TESTBED_SlaveConfiguration *reply;
2985 size_t xconfig_size;
2990 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
2991 slave_id = ntohl (msg->slave_id);
2992 op_id = GNUNET_ntohll (msg->operation_id);
2993 if ((slave_list_size <= slave_id) || (NULL == slave_list[slave_id]))
2995 send_operation_fail_msg (client, op_id, "Slave not found");
2996 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2999 slave = slave_list[slave_id];
3000 if (NULL == slave->cfg)
3002 send_operation_fail_msg (client, op_id,
3003 "Configuration not found (slave not started by me)");
3004 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3007 config = GNUNET_CONFIGURATION_serialize (slave->cfg, &config_size);
3008 xconfig_size = GNUNET_TESTBED_compress_config_ (config, config_size,
3010 GNUNET_free (config);
3011 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
3012 GNUNET_break (reply_size <= UINT16_MAX);
3013 GNUNET_break (config_size <= UINT16_MAX);
3014 reply = GNUNET_realloc (xconfig, reply_size);
3015 (void) memmove (&reply[1], reply, xconfig_size);
3016 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG);
3017 reply->header.size = htons ((uint16_t) reply_size);
3018 reply->slave_id = msg->slave_id;
3019 reply->operation_id = msg->operation_id;
3020 reply->config_size = htons ((uint16_t) config_size);
3021 queue_message (client, &reply->header);
3022 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3027 * Iterator over hash map entries.
3029 * @param cls closure
3030 * @param key current key code
3031 * @param value value in the hash map
3032 * @return GNUNET_YES if we should continue to
3037 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
3039 struct SharedService *ss = value;
3041 GNUNET_assert (GNUNET_YES ==
3042 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
3043 GNUNET_free (ss->name);
3050 * Task to clean up and shutdown nicely
3053 * @param tc the TaskContext from scheduler
3056 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3058 struct LCFContextQueue *lcfq;
3061 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
3062 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
3063 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
3065 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
3066 if (NULL != lcfq_head)
3068 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
3070 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
3071 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
3073 if (NULL != lcfq_head->lcf->rhandle)
3074 GNUNET_TESTBED_cancel_registration (lcfq_head->lcf->rhandle);
3076 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
3077 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
3079 GNUNET_free (lcfq->lcf->msg);
3080 GNUNET_free (lcfq->lcf);
3081 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
3084 /* Clear peer list */
3085 for (id = 0; id < peer_list_size; id++)
3086 if (NULL != peer_list[id])
3088 if (GNUNET_NO == peer_list[id]->is_remote)
3090 if (GNUNET_YES == peer_list[id]->details.local.is_running)
3091 GNUNET_TESTING_peer_stop (peer_list[id]->details.local.peer);
3092 GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
3093 GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
3095 GNUNET_free (peer_list[id]);
3097 GNUNET_free_non_null (peer_list);
3098 /* Clear host list */
3099 for (id = 0; id < host_list_size; id++)
3100 if (NULL != host_list[id])
3101 GNUNET_TESTBED_host_destroy (host_list[id]);
3102 GNUNET_free_non_null (host_list);
3103 /* Clear route list */
3104 for (id = 0; id < route_list_size; id++)
3105 if (NULL != route_list[id])
3106 GNUNET_free (route_list[id]);
3107 GNUNET_free_non_null (route_list);
3108 /* Clear slave_list */
3109 for (id = 0; id < slave_list_size; id++)
3110 if (NULL != slave_list[id])
3112 if (NULL != slave_list[id]->cfg)
3113 GNUNET_CONFIGURATION_destroy (slave_list[id]->cfg);
3114 if (NULL != slave_list[id]->controller)
3115 GNUNET_TESTBED_controller_disconnect (slave_list[id]->controller);
3116 if (NULL != slave_list[id]->controller_proc)
3117 GNUNET_TESTBED_controller_stop (slave_list[id]->controller_proc);
3118 GNUNET_free (slave_list[id]);
3120 GNUNET_free_non_null (slave_list);
3121 if (NULL != master_context)
3123 GNUNET_free_non_null (master_context->master_ip);
3124 if (NULL != master_context->system)
3125 GNUNET_TESTING_system_destroy (master_context->system, GNUNET_YES);
3126 GNUNET_free (master_context);
3127 master_context = NULL;
3129 GNUNET_free_non_null (hostname);
3134 * Callback for client disconnect
3137 * @param client the client which has disconnected
3140 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
3142 if (NULL == master_context)
3144 if (client == master_context->client)
3146 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
3147 GNUNET_SERVER_client_drop (client);
3148 /* should not be needed as we're terminated by failure to read
3149 * from stdin, but if stdin fails for some reason, this shouldn't
3150 * hurt for now --- might need to revise this later if we ever
3151 * decide that master connections might be temporarily down
3152 * for some reason */
3153 //GNUNET_SCHEDULER_shutdown ();
3161 * @param cls closure
3162 * @param server the initialized server
3163 * @param cfg configuration to use
3166 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
3167 const struct GNUNET_CONFIGURATION_Handle *cfg)
3169 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
3170 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
3171 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
3172 {&handle_configure_shared_service, NULL,
3173 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
3174 {&handle_link_controllers, NULL,
3175 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
3176 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
3177 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER,
3178 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
3179 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER,
3180 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
3181 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER,
3182 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
3183 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG,
3184 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
3185 {&handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT,
3186 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
3187 {&handle_overlay_request_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT,
3189 {handle_slave_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG,
3190 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
3194 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
3195 (cfg, "testbed", "HOSTNAME", &hostname));
3196 GNUNET_SERVER_add_handlers (server, message_handlers);
3197 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
3198 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
3200 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
3201 &shutdown_task, NULL);
3202 LOG_DEBUG ("Testbed startup complete\n");
3203 event_mask = GNUNET_TESTBED_ET_OPERATION_FINISHED;
3208 * The starting point of execution
3211 main (int argc, char *const *argv)
3213 //sleep (15); /* Debugging */
3214 return (GNUNET_OK ==
3215 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
3216 &testbed_run, NULL)) ? 0 : 1;
3219 /* end of gnunet-service-testbed.c */