2 This file is part of GNUnet.
3 (C) 2008--2013 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
27 #include "gnunet-service-testbed.h"
39 struct GNUNET_CONFIGURATION_Handle *our_config;
42 * The master context; generated with the first INIT message
44 struct Context *GST_context;
47 * A list of directly linked neighbours
49 struct Slave **GST_slave_list;
52 * A list of peers we know about
54 struct Peer **GST_peer_list;
59 struct GNUNET_TESTBED_Host **GST_host_list;
62 * DLL head for forwarded operation contexts
64 struct ForwardedOperationContext *fopcq_head;
67 * DLL tail for forwarded operation contexts
69 struct ForwardedOperationContext *fopcq_tail;
72 * Operation queue for open file descriptors
74 struct OperationQueue *GST_opq_openfds;
77 * Timeout for operations which may take some time
79 const struct GNUNET_TIME_Relative GST_timeout;
82 * The size of the host list
84 unsigned int GST_host_list_size;
87 * The size of directly linked neighbours list
89 unsigned int GST_slave_list_size;
92 * The size of the peer list
94 unsigned int GST_peer_list_size;
97 /***********************************/
98 /* Local definitions and variables */
99 /***********************************/
102 * The message queue for sending messages to clients
107 * The message to be sent
109 struct GNUNET_MessageHeader *msg;
112 * The client to send the message to
114 struct GNUNET_SERVER_Client *client;
117 * next pointer for DLL
119 struct MessageQueue *next;
122 * prev pointer for DLL
124 struct MessageQueue *prev;
128 * Our hostname; we give this to all the peers we start
130 static char *hostname;
133 * Current Transmit Handle; NULL if no notify transmit exists currently
135 static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
138 * The head for the LCF queue
140 static struct LCFContextQueue *lcfq_head;
143 * The tail for the LCF queue
145 static struct LCFContextQueue *lcfq_tail;
148 * The message queue head
150 static struct MessageQueue *mq_head;
153 * The message queue tail
155 static struct MessageQueue *mq_tail;
158 * The hashmap of shared services
160 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
165 static struct Route **route_list;
168 * The event mask for the events we listen from sub-controllers
170 static uint64_t event_mask;
173 * The size of the route list
175 static unsigned int route_list_size;
178 * The lcf_task handle
180 static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
183 * The shutdown task handle
185 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
189 * Function called to notify a client about the connection begin ready to queue
190 * more data. "buf" will be NULL and "size" zero if the connection was closed
191 * for writing in the meantime.
194 * @param size number of bytes available in buf
195 * @param buf where the callee should write the message
196 * @return number of bytes written to buf
199 transmit_ready_notify (void *cls, size_t size, void *buf)
201 struct MessageQueue *mq_entry;
203 transmit_handle = NULL;
205 GNUNET_assert (NULL != mq_entry);
208 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
209 size = ntohs (mq_entry->msg->size);
210 memcpy (buf, mq_entry->msg, size);
211 GNUNET_free (mq_entry->msg);
212 GNUNET_SERVER_client_drop (mq_entry->client);
213 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
214 GNUNET_free (mq_entry);
216 if (NULL != mq_entry)
218 GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
219 ntohs (mq_entry->msg->size),
220 GNUNET_TIME_UNIT_FOREVER_REL,
221 &transmit_ready_notify, NULL);
227 * Queues a message in send queue for sending to the service
229 * @param client the client to whom the queued message has to be sent
230 * @param msg the message to queue
233 GST_queue_message (struct GNUNET_SERVER_Client *client,
234 struct GNUNET_MessageHeader *msg)
236 struct MessageQueue *mq_entry;
240 type = ntohs (msg->type);
241 size = ntohs (msg->size);
242 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
243 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
244 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
246 mq_entry->client = client;
247 GNUNET_SERVER_client_keep (client);
248 LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type,
250 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
251 if (NULL == transmit_handle)
253 GNUNET_SERVER_notify_transmit_ready (client, size,
254 GNUNET_TIME_UNIT_FOREVER_REL,
255 &transmit_ready_notify, NULL);
260 * Similar to GNUNET_array_grow(); however instead of calling GNUNET_array_grow()
261 * several times we call it only once. The array is also made to grow in steps
264 * @param ptr the array pointer to grow
265 * @param size the size of array
266 * @param accommodate_size the size which the array has to accommdate; after
267 * this call the array will be big enough to accommdate sizes upto
270 #define array_grow_large_enough(ptr, size, accommodate_size) \
273 unsigned int growth_size; \
274 GNUNET_assert (size <= accommodate_size); \
275 growth_size = size; \
276 while (growth_size <= accommodate_size) \
277 growth_size += LIST_GROW_STEP; \
278 GNUNET_array_grow (ptr, size, growth_size); \
279 GNUNET_assert (size > accommodate_size); \
284 * Function to add a host to the current list of known hosts
286 * @param host the host to add
287 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
291 host_list_add (struct GNUNET_TESTBED_Host *host)
295 host_id = GNUNET_TESTBED_host_get_id_ (host);
296 if (GST_host_list_size <= host_id)
297 array_grow_large_enough (GST_host_list, GST_host_list_size, host_id);
298 if (NULL != GST_host_list[host_id])
300 LOG_DEBUG ("A host with id: %u already exists\n", host_id);
301 return GNUNET_SYSERR;
303 GST_host_list[host_id] = host;
309 * Adds a route to the route list
311 * @param route the route to add
314 route_list_add (struct Route *route)
316 if (route->dest >= route_list_size)
317 array_grow_large_enough (route_list, route_list_size, route->dest);
318 GNUNET_assert (NULL == route_list[route->dest]);
319 route_list[route->dest] = route;
324 * Adds a slave to the slave array
326 * @param slave the slave controller to add
329 slave_list_add (struct Slave *slave)
331 if (slave->host_id >= GST_slave_list_size)
332 array_grow_large_enough (GST_slave_list, GST_slave_list_size,
334 GNUNET_assert (NULL == GST_slave_list[slave->host_id]);
335 GST_slave_list[slave->host_id] = slave;
340 * Adds a peer to the peer array
342 * @param peer the peer to add
345 peer_list_add (struct Peer *peer)
347 if (peer->id >= GST_peer_list_size)
348 array_grow_large_enough (GST_peer_list, GST_peer_list_size, peer->id);
349 GNUNET_assert (NULL == GST_peer_list[peer->id]);
350 GST_peer_list[peer->id] = peer;
355 * Removes a the give peer from the peer array
357 * @param peer the peer to be removed
360 peer_list_remove (struct Peer *peer)
362 unsigned int orig_size;
365 GST_peer_list[peer->id] = NULL;
366 orig_size = GST_peer_list_size;
367 while (GST_peer_list_size >= LIST_GROW_STEP)
369 for (id = GST_peer_list_size - 1;
370 (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX);
372 if (NULL != GST_peer_list[id])
374 if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1))
376 GST_peer_list_size -= LIST_GROW_STEP;
378 if (orig_size == GST_peer_list_size)
381 GNUNET_realloc (GST_peer_list,
382 sizeof (struct Peer *) * GST_peer_list_size);
387 * Finds the route with directly connected host as destination through which
388 * the destination host can be reached
390 * @param host_id the id of the destination host
391 * @return the route with directly connected destination host; NULL if no route
395 GST_find_dest_route (uint32_t host_id)
399 if (route_list_size <= host_id)
401 while (NULL != (route = route_list[host_id]))
403 if (route->thru == GST_context->host_id)
405 host_id = route->thru;
412 * Routes message to a host given its host_id
414 * @param host_id the id of the destination host
415 * @param msg the message to be routed
418 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
425 * Send operation failure message to client
427 * @param client the client to which the failure message has to be sent to
428 * @param operation_id the id of the failed operation
429 * @param emsg the error message; can be NULL
432 GST_send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
433 uint64_t operation_id, const char *emsg)
435 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
439 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
440 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
442 msg = GNUNET_malloc (msize);
443 msg->header.size = htons (msize);
444 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT);
445 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
446 msg->operation_id = GNUNET_htonll (operation_id);
448 memcpy (&msg[1], emsg, emsg_len);
449 GST_queue_message (client, &msg->header);
454 * Function to send generic operation success message to given client
456 * @param client the client to send the message to
457 * @param operation_id the id of the operation which was successful
460 send_operation_success_msg (struct GNUNET_SERVER_Client *client,
461 uint64_t operation_id)
463 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
466 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
467 msg = GNUNET_malloc (msize);
468 msg->header.size = htons (msize);
470 htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS);
471 msg->operation_id = GNUNET_htonll (operation_id);
472 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
473 GST_queue_message (client, &msg->header);
478 * Function to send a failure reponse for controller link operation
480 * @param client the client to send the message to
481 * @param operation_id the operation ID of the controller link request
482 * @param cfg the configuration with which the delegated controller is started.
483 * Can be NULL if the delegated controller is not started but just
485 * @param emsg set to an error message explaining why the controller link
486 * failed. Setting this to NULL signifies success. !This should be
487 * NULL if cfg is set!
490 send_controller_link_response (struct GNUNET_SERVER_Client *client,
491 uint64_t operation_id,
492 const struct GNUNET_CONFIGURATION_Handle
496 struct GNUNET_TESTBED_ControllerLinkResponse *msg;
502 GNUNET_assert ((NULL == cfg) || (NULL == emsg));
506 msize = sizeof (struct GNUNET_TESTBED_ControllerLinkResponse);
509 xconfig = GNUNET_TESTBED_compress_cfg_ (cfg,
512 msize += xconfig_size;
515 msize += strlen (emsg);
516 msg = GNUNET_malloc (msize);
517 msg->header.type = htons
518 (GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT);
519 msg->header.size = htons (msize);
521 msg->success = htons (GNUNET_YES);
522 msg->operation_id = GNUNET_htonll (operation_id);
523 msg->config_size = htons ((uint16_t) config_size);
525 memcpy (&msg[1], xconfig, xconfig_size);
527 memcpy (&msg[1], emsg, strlen (emsg));
528 GST_queue_message (client, &msg->header);
532 * Callback which will be called after a host registration succeeded or failed
534 * @param cls the handle to the slave at which the registration is completed
535 * @param emsg the error message; NULL if host registration is successful
538 hr_completion (void *cls, const char *emsg);
542 * Attempts to register the next host in the host registration queue
544 * @param slave the slave controller whose host registration queue is checked
545 * for host registrations
548 register_next_host (struct Slave *slave)
550 struct HostRegistration *hr;
552 hr = slave->hr_dll_head;
553 GNUNET_assert (NULL != hr);
554 GNUNET_assert (NULL == slave->rhandle);
555 LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n",
556 GNUNET_TESTBED_host_get_id_ (hr->host),
557 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
559 GNUNET_TESTBED_register_host (slave->controller, hr->host, hr_completion,
565 * Callback which will be called to after a host registration succeeded or failed
567 * @param cls the handle to the slave at which the registration is completed
568 * @param emsg the error message; NULL if host registration is successful
571 hr_completion (void *cls, const char *emsg)
573 struct Slave *slave = cls;
574 struct HostRegistration *hr;
576 slave->rhandle = NULL;
577 hr = slave->hr_dll_head;
578 GNUNET_assert (NULL != hr);
579 LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u successful\n",
580 GNUNET_TESTBED_host_get_id_ (hr->host),
581 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
582 GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail, hr);
584 hr->cb (hr->cb_cls, emsg);
586 if (NULL != slave->hr_dll_head)
587 register_next_host (slave);
592 * Adds a host registration's request to a slave's registration queue
594 * @param slave the slave controller at which the given host has to be
596 * @param cb the host registration completion callback
597 * @param cb_cls the closure for the host registration completion callback
598 * @param host the host which has to be registered
601 GST_queue_host_registration (struct Slave *slave,
602 GNUNET_TESTBED_HostRegistrationCompletion cb,
603 void *cb_cls, struct GNUNET_TESTBED_Host *host)
605 struct HostRegistration *hr;
608 LOG (GNUNET_ERROR_TYPE_DEBUG,
609 "Queueing host registration for host %u at %u\n",
610 GNUNET_TESTBED_host_get_id_ (host),
611 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
612 hr = GNUNET_malloc (sizeof (struct HostRegistration));
616 call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO;
617 GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head, slave->hr_dll_tail, hr);
618 if (GNUNET_YES == call_register)
619 register_next_host (slave);
624 * The Link Controller forwarding task
626 * @param cls the LCFContext
627 * @param tc the Task context from scheduler
630 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
634 * Completion callback for host registrations while forwarding Link Controller messages
636 * @param cls the LCFContext
637 * @param emsg the error message; NULL if host registration is successful
640 lcf_proc_cc (void *cls, const char *emsg)
642 struct LCFContext *lcf = cls;
644 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
649 goto registration_error;
650 lcf->state = DELEGATED_HOST_REGISTERED;
651 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
653 case DELEGATED_HOST_REGISTERED:
655 goto registration_error;
656 lcf->state = SLAVE_HOST_REGISTERED;
657 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
660 GNUNET_assert (0); /* Shouldn't reach here */
665 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
667 lcf->state = FINISHED;
668 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
673 * Callback to relay the reply msg of a forwarded operation back to the client
675 * @param cls ForwardedOperationContext
676 * @param msg the message to relay
679 GST_forwarded_operation_reply_relay (void *cls,
680 const struct GNUNET_MessageHeader *msg)
682 struct ForwardedOperationContext *fopc = cls;
683 struct GNUNET_MessageHeader *dup_msg;
686 msize = ntohs (msg->size);
687 LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type),
689 dup_msg = GNUNET_copy_message (msg);
690 GST_queue_message (fopc->client, dup_msg);
691 GNUNET_SERVER_client_drop (fopc->client);
692 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
693 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
699 * Task to free resources when forwarded operation has been timedout
701 * @param cls the ForwardedOperationContext
702 * @param tc the task context from scheduler
705 GST_forwarded_operation_timeout (void *cls,
706 const struct GNUNET_SCHEDULER_TaskContext *tc)
708 struct ForwardedOperationContext *fopc = cls;
710 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
711 LOG (GNUNET_ERROR_TYPE_WARNING, "A forwarded operation has timed out\n");
712 GST_send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
713 GNUNET_SERVER_client_drop (fopc->client);
714 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
720 * The Link Controller forwarding task
722 * @param cls the LCFContext
723 * @param tc the Task context from scheduler
726 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
730 * Task to free resources when forwarded link controllers has been timedout
732 * @param cls the LCFContext
733 * @param tc the task context from scheduler
736 lcf_forwarded_operation_timeout (void *cls,
737 const struct GNUNET_SCHEDULER_TaskContext *tc)
739 struct LCFContext *lcf = cls;
741 lcf->timeout_task = GNUNET_SCHEDULER_NO_TASK;
742 // GST_forwarded_operation_timeout (lcf->fopc, tc);
743 LOG (GNUNET_ERROR_TYPE_WARNING,
744 "A forwarded controller link operation has timed out\n");
745 send_controller_link_response (lcf->client, lcf->operation_id, NULL, "Timeout");
746 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
747 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
752 * The Link Controller forwarding task
754 * @param cls the LCFContext
755 * @param tc the Task context from scheduler
758 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
760 struct LCFContext *lcf = cls;
761 struct LCFContextQueue *lcfq;
763 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
768 GNUNET_TESTBED_is_host_registered_ (GST_host_list
769 [lcf->delegated_host_id],
770 lcf->gateway->controller))
772 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
773 GST_host_list[lcf->delegated_host_id]);
777 lcf->state = DELEGATED_HOST_REGISTERED;
778 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
781 case DELEGATED_HOST_REGISTERED:
783 GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id],
784 lcf->gateway->controller))
786 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
787 GST_host_list[lcf->slave_host_id]);
791 lcf->state = SLAVE_HOST_REGISTERED;
792 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
795 case SLAVE_HOST_REGISTERED:
796 lcf->op = GNUNET_TESTBED_controller_link (lcf,
797 lcf->gateway->controller,
798 GST_host_list[lcf->delegated_host_id],
799 GST_host_list[lcf->slave_host_id],
801 lcf->is_subordinate);
803 GNUNET_SCHEDULER_add_delayed (GST_timeout, &lcf_forwarded_operation_timeout,
805 lcf->state = FINISHED;
809 GNUNET_assert (lcfq->lcf == lcf);
810 GNUNET_assert (NULL != lcf->cfg);
811 GNUNET_CONFIGURATION_destroy (lcf->cfg);
812 GNUNET_SERVER_client_drop (lcf->client);
813 GNUNET_TESTBED_operation_done (lcf->op);
815 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
817 if (NULL != lcfq_head)
819 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
825 * Callback for event from slave controllers
827 * @param cls struct Slave *
828 * @param event information about the event
831 slave_event_callback (void *cls,
832 const struct GNUNET_TESTBED_EventInformation *event)
834 struct RegisteredHostContext *rhc;
835 struct LCFContext *lcf;
836 struct GNUNET_CONFIGURATION_Handle *cfg;
837 struct GNUNET_TESTBED_Operation *old_op;
839 /* We currently only get here when working on RegisteredHostContexts and
841 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
842 rhc = event->details.operation_finished.op_cls;
843 if (CLOSURE_TYPE_RHC == rhc->type)
845 GNUNET_assert (rhc->sub_op == event->details.operation_finished.operation);
849 cfg = event->details.operation_finished.generic;
850 old_op = rhc->sub_op;
851 rhc->state = RHC_LINK;
853 GNUNET_TESTBED_controller_link (rhc, rhc->gateway->controller,
854 rhc->reg_host, rhc->host, cfg,
856 GNUNET_TESTBED_operation_done (old_op);
859 LOG_DEBUG ("OL: Linking controllers successfull\n");
860 GNUNET_TESTBED_operation_done (rhc->sub_op);
862 rhc->state = RHC_OL_CONNECT;
863 GST_process_next_focc (rhc);
870 lcf = event->details.operation_finished.op_cls;
871 if (CLOSURE_TYPE_LCF == lcf->type)
873 GNUNET_assert (lcf->op == event->details.operation_finished.operation);
874 GNUNET_assert (FINISHED == lcf->state);
875 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != lcf->timeout_task);
876 GNUNET_SCHEDULER_cancel (lcf->timeout_task);
877 if (NULL == event->details.operation_finished.emsg)
878 send_controller_link_response (lcf->client, lcf->operation_id,
879 GNUNET_TESTBED_host_get_cfg_
880 (GST_host_list[lcf->delegated_host_id]),
883 send_controller_link_response (lcf->client, lcf->operation_id,
885 event->details.operation_finished.emsg);
886 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
887 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
895 * Callback to signal successfull startup of the controller process
897 * @param cls the handle to the slave whose status is to be found here
898 * @param cfg the configuration with which the controller has been started;
899 * NULL if status is not GNUNET_OK
900 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
901 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
904 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
907 struct Slave *slave = cls;
908 struct LinkControllersContext *lcc;
911 if (GNUNET_SYSERR == status)
913 slave->controller_proc = NULL;
914 GST_slave_list[slave->host_id] = NULL;
917 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
918 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
922 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
923 event_mask, &slave_event_callback,
925 if (NULL != slave->controller)
927 send_controller_link_response (lcc->client, lcc->operation_id, cfg, NULL);
931 send_controller_link_response (lcc->client, lcc->operation_id, NULL,
932 "Could not connect to delegated controller");
933 GNUNET_TESTBED_controller_stop (slave->controller_proc);
934 GST_slave_list[slave->host_id] = NULL;
942 if (NULL != lcc->client)
944 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
945 GNUNET_SERVER_client_drop (lcc->client);
956 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
959 * @param client identification of the client
960 * @param message the actual message
963 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
964 const struct GNUNET_MessageHeader *message)
966 const struct GNUNET_TESTBED_InitMessage *msg;
967 struct GNUNET_TESTBED_Host *host;
968 const char *controller_hostname;
971 if (NULL != GST_context)
973 LOG_DEBUG ("We are being connected to laterally\n");
974 GNUNET_SERVER_receive_done (client, GNUNET_OK);
977 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
978 msize = ntohs (message->size);
979 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
982 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
985 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
986 controller_hostname = (const char *) &msg[1];
987 if ('\0' != controller_hostname[msize - 1])
990 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
993 GST_context = GNUNET_malloc (sizeof (struct Context));
994 GNUNET_SERVER_client_keep (client);
995 GST_context->client = client;
996 GST_context->host_id = ntohl (msg->host_id);
997 GST_context->master_ip = GNUNET_strdup (controller_hostname);
998 LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
999 GST_context->system =
1000 GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
1003 GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
1004 GST_context->master_ip, NULL,
1006 host_list_add (host);
1007 LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id);
1008 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1013 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1016 * @param client identification of the client
1017 * @param message the actual message
1020 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
1021 const struct GNUNET_MessageHeader *message)
1023 struct GNUNET_TESTBED_Host *host;
1024 const struct GNUNET_TESTBED_AddHostMessage *msg;
1025 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
1026 struct GNUNET_CONFIGURATION_Handle *host_cfg;
1032 uint16_t username_length;
1033 uint16_t hostname_length;
1034 uint16_t reply_size;
1037 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
1038 msize = ntohs (msg->header.size);
1039 if (msize <= sizeof (struct GNUNET_TESTBED_AddHostMessage))
1041 GNUNET_break_op (0);
1042 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1045 username_length = ntohs (msg->username_length);
1046 hostname_length = ntohs (msg->hostname_length);
1047 /* msg must contain hostname */
1048 if ((msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
1050 || (0 == hostname_length))
1052 GNUNET_break_op (0);
1053 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1056 /* msg must contain configuration */
1057 if (msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
1058 username_length + hostname_length))
1060 GNUNET_break_op (0);
1061 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1067 if (0 != username_length)
1069 username = GNUNET_malloc (username_length + 1);
1070 strncpy (username, ptr, username_length);
1071 ptr += username_length;
1073 hostname = GNUNET_malloc (hostname_length + 1);
1074 strncpy (hostname, ptr, hostname_length);
1075 ptr += hostname_length;
1076 if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (message)))
1078 GNUNET_free_non_null (username);
1079 GNUNET_free_non_null (hostname);
1080 GNUNET_break_op (0);
1081 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1084 host_id = ntohl (msg->host_id);
1085 LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
1086 LOG_DEBUG ("-------host id: %u\n", host_id);
1087 LOG_DEBUG ("-------hostname: %s\n", hostname);
1088 if (NULL != username)
1089 LOG_DEBUG ("-------username: %s\n", username);
1091 LOG_DEBUG ("-------username: <not given>\n");
1092 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1094 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1095 host_cfg, ntohs (msg->ssh_port));
1096 GNUNET_free_non_null (username);
1097 GNUNET_free (hostname);
1098 GNUNET_CONFIGURATION_destroy (host_cfg);
1101 GNUNET_break_op (0);
1102 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1105 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1106 if (GNUNET_OK != host_list_add (host))
1108 /* We are unable to add a host */
1109 emsg = "A host exists with given host-id";
1110 LOG_DEBUG ("%s: %u", emsg, host_id);
1111 GNUNET_TESTBED_host_destroy (host);
1112 reply_size += strlen (emsg) + 1;
1113 reply = GNUNET_malloc (reply_size);
1114 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1118 LOG_DEBUG ("Added host %u at %u\n", host_id, GST_context->host_id);
1119 reply = GNUNET_malloc (reply_size);
1121 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS);
1122 reply->header.size = htons (reply_size);
1123 reply->host_id = htonl (host_id);
1124 GST_queue_message (client, &reply->header);
1125 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1130 * Iterator over hash map entries.
1132 * @param cls closure
1133 * @param key current key code
1134 * @param value value in the hash map
1135 * @return GNUNET_YES if we should continue to
1140 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1142 struct SharedService *queried_ss = cls;
1143 struct SharedService *ss = value;
1145 if (0 == strcmp (ss->name, queried_ss->name))
1153 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1156 * @param client identification of the client
1157 * @param message the actual message
1160 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1161 const struct GNUNET_MessageHeader *message)
1163 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1164 struct SharedService *ss;
1166 struct GNUNET_HashCode hash;
1168 uint16_t service_name_size;
1170 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1171 msg_size = ntohs (message->size);
1172 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1175 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1179 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1180 service_name = (char *) &msg[1];
1181 if ('\0' != service_name[service_name_size - 1])
1184 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1187 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1188 service_name, ntohl (msg->num_peers));
1189 if (ntohl (msg->host_id) != GST_context->host_id)
1191 route_message (ntohl (msg->host_id), message);
1192 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1195 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1196 ss = GNUNET_malloc (sizeof (struct SharedService));
1197 ss->name = strdup (service_name);
1198 ss->num_shared = ntohl (msg->num_peers);
1199 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1200 if (GNUNET_SYSERR ==
1201 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1202 &ss_exists_iterator, ss))
1204 LOG (GNUNET_ERROR_TYPE_WARNING,
1205 "Service %s already configured as a shared service. "
1206 "Ignoring service sharing request \n", ss->name);
1207 GNUNET_free (ss->name);
1211 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1212 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1217 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1220 * @param client identification of the client
1221 * @param message the actual message
1224 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1225 const struct GNUNET_MessageHeader *message)
1227 const struct GNUNET_TESTBED_ControllerLinkRequest *msg;
1228 struct GNUNET_CONFIGURATION_Handle *cfg;
1229 struct LCFContextQueue *lcfq;
1230 struct Route *route;
1231 struct Route *new_route;
1232 uint32_t delegated_host_id;
1233 uint32_t slave_host_id;
1236 if (NULL == GST_context)
1239 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1242 msize = ntohs (message->size);
1243 if (sizeof (struct GNUNET_TESTBED_ControllerLinkRequest) >= msize)
1246 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1249 msg = (const struct GNUNET_TESTBED_ControllerLinkRequest *) message;
1250 delegated_host_id = ntohl (msg->delegated_host_id);
1251 if (delegated_host_id == GST_context->host_id)
1254 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1255 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1258 if ((delegated_host_id >= GST_host_list_size) ||
1259 (NULL == GST_host_list[delegated_host_id]))
1261 LOG (GNUNET_ERROR_TYPE_WARNING,
1262 "Delegated host %u not registered with us\n", delegated_host_id);
1263 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1266 slave_host_id = ntohl (msg->slave_host_id);
1267 if ((slave_host_id >= GST_host_list_size) ||
1268 (NULL == GST_host_list[slave_host_id]))
1270 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n",
1272 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1275 if (slave_host_id == delegated_host_id)
1277 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1281 cfg = GNUNET_TESTBED_extract_config_ (message); /* destroy cfg here or in lcfcontext */
1284 GNUNET_break (0); /* Configuration parsing error */
1285 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1288 if (slave_host_id == GST_context->host_id) /* Link from us */
1290 struct Slave *slave;
1291 struct LinkControllersContext *lcc;
1293 if ((delegated_host_id < GST_slave_list_size) &&
1294 (NULL != GST_slave_list[delegated_host_id]))
1297 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1300 slave = GNUNET_malloc (sizeof (struct Slave));
1301 slave->host_id = delegated_host_id;
1302 slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
1303 slave_list_add (slave);
1304 if (1 != msg->is_subordinate)
1307 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
1308 event_mask, &slave_event_callback,
1310 if (NULL != slave->controller)
1311 send_controller_link_response (client,
1312 GNUNET_ntohll (msg->operation_id),
1316 send_controller_link_response (client,
1317 GNUNET_ntohll (msg->operation_id),
1319 "Could not connect to delegated controller");
1320 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1323 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1324 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1325 GNUNET_SERVER_client_keep (client);
1326 lcc->client = client;
1328 slave->controller_proc =
1329 GNUNET_TESTBED_controller_start (GST_context->master_ip,
1330 GST_host_list[slave->host_id], cfg,
1331 &slave_status_callback, slave);
1332 GNUNET_CONFIGURATION_destroy (cfg);
1333 new_route = GNUNET_malloc (sizeof (struct Route));
1334 new_route->dest = delegated_host_id;
1335 new_route->thru = GST_context->host_id;
1336 route_list_add (new_route);
1340 /* Route the request */
1341 if (slave_host_id >= route_list_size)
1343 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1344 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1347 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1348 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1349 lcfq->lcf->type = CLOSURE_TYPE_LCF;
1350 lcfq->lcf->delegated_host_id = delegated_host_id;
1351 lcfq->lcf->slave_host_id = slave_host_id;
1352 route = GST_find_dest_route (slave_host_id);
1353 GNUNET_assert (NULL != route); /* because we add routes carefully */
1354 GNUNET_assert (route->dest < GST_slave_list_size);
1355 GNUNET_assert (NULL != GST_slave_list[route->dest]);
1356 lcfq->lcf->cfg = cfg;
1357 lcfq->lcf->is_subordinate = msg->is_subordinate;
1358 lcfq->lcf->state = INIT;
1359 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1360 lcfq->lcf->gateway = GST_slave_list[route->dest];
1361 GNUNET_SERVER_client_keep (client);
1362 lcfq->lcf->client = client;
1363 if (NULL == lcfq_head)
1365 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1366 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1367 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1370 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1371 /* FIXME: Adding a new route should happen after the controllers are linked
1373 if (1 != msg->is_subordinate)
1375 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1378 if ((delegated_host_id < route_list_size) &&
1379 (NULL != route_list[delegated_host_id]))
1381 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1382 * with is subordinate flag set to GNUNET_YES? */
1383 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1386 new_route = GNUNET_malloc (sizeof (struct Route));
1387 new_route->dest = delegated_host_id;
1388 new_route->thru = route->dest;
1389 route_list_add (new_route);
1390 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1395 * The task to be executed if the forwarded peer create operation has been
1398 * @param cls the FowardedOperationContext
1399 * @param tc the TaskContext from the scheduler
1402 peer_create_forward_timeout (void *cls,
1403 const struct GNUNET_SCHEDULER_TaskContext *tc)
1405 struct ForwardedOperationContext *fopc = cls;
1407 GNUNET_free (fopc->cls);
1408 GST_forwarded_operation_timeout (fopc, tc);
1413 * Callback to be called when forwarded peer create operation is successfull. We
1414 * have to relay the reply msg back to the client
1416 * @param cls ForwardedOperationContext
1417 * @param msg the peer create success message
1420 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1422 struct ForwardedOperationContext *fopc = cls;
1423 struct Peer *remote_peer;
1425 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS)
1427 GNUNET_assert (NULL != fopc->cls);
1428 remote_peer = fopc->cls;
1429 peer_list_add (remote_peer);
1431 GST_forwarded_operation_reply_relay (fopc, msg);
1436 * Function to destroy a peer
1438 * @param peer the peer structure to destroy
1441 GST_destroy_peer (struct Peer *peer)
1443 GNUNET_break (0 == peer->reference_cnt);
1444 if (GNUNET_YES == peer->is_remote)
1446 peer_list_remove (peer);
1450 if (GNUNET_YES == peer->details.local.is_running)
1452 GNUNET_TESTING_peer_stop (peer->details.local.peer);
1453 peer->details.local.is_running = GNUNET_NO;
1455 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1456 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
1457 peer_list_remove (peer);
1463 * Callback to be called when forwarded peer destroy operation is successfull. We
1464 * have to relay the reply msg back to the client
1466 * @param cls ForwardedOperationContext
1467 * @param msg the peer create success message
1470 peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1472 struct ForwardedOperationContext *fopc = cls;
1473 struct Peer *remote_peer;
1475 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS ==
1478 remote_peer = fopc->cls;
1479 GNUNET_assert (NULL != remote_peer);
1480 remote_peer->destroy_flag = GNUNET_YES;
1481 if (0 == remote_peer->reference_cnt)
1482 GST_destroy_peer (remote_peer);
1484 GST_forwarded_operation_reply_relay (fopc, msg);
1490 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1493 * @param client identification of the client
1494 * @param message the actual message
1497 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1498 const struct GNUNET_MessageHeader *message)
1500 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1501 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1502 struct GNUNET_CONFIGURATION_Handle *cfg;
1503 struct ForwardedOperationContext *fo_ctxt;
1504 struct Route *route;
1509 uint32_t config_size;
1515 msize = ntohs (message->size);
1516 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1518 GNUNET_break (0); /* We need configuration */
1519 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1522 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1523 host_id = ntohl (msg->host_id);
1524 peer_id = ntohl (msg->peer_id);
1525 if (UINT32_MAX == peer_id)
1527 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1528 "Cannot create peer with given ID");
1529 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1532 if (host_id == GST_context->host_id)
1536 /* We are responsible for this peer */
1537 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1538 config_size = ntohl (msg->config_size);
1539 config = GNUNET_malloc (config_size);
1540 dest_size = config_size;
1543 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1544 (const Bytef *) &msg[1], (uLong) msize)))
1546 GNUNET_break (0); /* uncompression error */
1547 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1550 if (config_size != dest_size)
1552 GNUNET_break (0); /* Uncompressed config size mismatch */
1553 GNUNET_free (config);
1554 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1557 cfg = GNUNET_CONFIGURATION_create ();
1559 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1561 GNUNET_break (0); /* Configuration parsing error */
1562 GNUNET_free (config);
1563 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1566 GNUNET_free (config);
1567 GNUNET_CONFIGURATION_set_value_number (cfg, "TESTBED", "PEERID",
1568 (unsigned long long) peer_id);
1569 peer = GNUNET_malloc (sizeof (struct Peer));
1570 peer->is_remote = GNUNET_NO;
1571 peer->details.local.cfg = cfg;
1573 LOG_DEBUG ("Creating peer with id: %u\n", (unsigned int) peer->id);
1574 peer->details.local.peer =
1575 GNUNET_TESTING_peer_configure (GST_context->system,
1576 peer->details.local.cfg, peer->id,
1577 NULL /* Peer id */ ,
1579 if (NULL == peer->details.local.peer)
1581 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1585 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1588 peer->details.local.is_running = GNUNET_NO;
1589 peer_list_add (peer);
1591 GNUNET_malloc (sizeof
1592 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1593 reply->header.size =
1594 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1595 reply->header.type =
1596 htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS);
1597 reply->peer_id = msg->peer_id;
1598 reply->operation_id = msg->operation_id;
1599 GST_queue_message (client, &reply->header);
1600 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1604 /* Forward peer create request */
1605 route = GST_find_dest_route (host_id);
1609 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1613 peer = GNUNET_malloc (sizeof (struct Peer));
1614 peer->is_remote = GNUNET_YES;
1616 peer->details.remote.slave = GST_slave_list[route->dest];
1617 peer->details.remote.remote_host_id = host_id;
1618 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1619 GNUNET_SERVER_client_keep (client);
1620 fo_ctxt->client = client;
1621 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1622 fo_ctxt->cls = peer; //GST_slave_list[route->dest]->controller;
1623 fo_ctxt->type = OP_PEER_CREATE;
1625 GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list
1626 [route->dest]->controller,
1627 fo_ctxt->operation_id,
1629 peer_create_success_cb, fo_ctxt);
1630 fo_ctxt->timeout_task =
1631 GNUNET_SCHEDULER_add_delayed (GST_timeout, &peer_create_forward_timeout,
1633 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
1634 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1639 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1642 * @param client identification of the client
1643 * @param message the actual message
1646 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
1647 const struct GNUNET_MessageHeader *message)
1649 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1650 struct ForwardedOperationContext *fopc;
1654 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1655 peer_id = ntohl (msg->peer_id);
1656 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1657 peer_id, GNUNET_ntohll (msg->operation_id));
1658 if ((GST_peer_list_size <= peer_id) || (NULL == GST_peer_list[peer_id]))
1660 LOG (GNUNET_ERROR_TYPE_ERROR,
1661 "Asked to destroy a non existent peer with id: %u\n", peer_id);
1662 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1663 "Peer doesn't exist");
1664 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1667 peer = GST_peer_list[peer_id];
1668 if (GNUNET_YES == peer->is_remote)
1670 /* Forward the destory message to sub controller */
1671 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1672 GNUNET_SERVER_client_keep (client);
1673 fopc->client = client;
1675 fopc->type = OP_PEER_DESTROY;
1676 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1678 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1680 fopc->operation_id, &msg->header,
1681 &peer_destroy_success_cb, fopc);
1682 fopc->timeout_task =
1683 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1685 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1686 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1689 peer->destroy_flag = GNUNET_YES;
1690 if (0 == peer->reference_cnt)
1691 GST_destroy_peer (peer);
1693 LOG (GNUNET_ERROR_TYPE_DEBUG,
1694 "Delaying peer destroy as peer is currently in use\n");
1695 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1696 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1701 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1704 * @param client identification of the client
1705 * @param message the actual message
1708 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
1709 const struct GNUNET_MessageHeader *message)
1711 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1712 struct GNUNET_TESTBED_PeerEventMessage *reply;
1713 struct ForwardedOperationContext *fopc;
1717 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
1718 peer_id = ntohl (msg->peer_id);
1719 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1722 LOG (GNUNET_ERROR_TYPE_ERROR,
1723 "Asked to start a non existent peer with id: %u\n", peer_id);
1724 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1727 peer = GST_peer_list[peer_id];
1728 if (GNUNET_YES == peer->is_remote)
1730 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1731 GNUNET_SERVER_client_keep (client);
1732 fopc->client = client;
1733 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1734 fopc->type = OP_PEER_START;
1736 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1738 fopc->operation_id, &msg->header,
1739 &GST_forwarded_operation_reply_relay,
1741 fopc->timeout_task =
1742 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1744 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1745 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1748 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
1750 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1752 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1755 peer->details.local.is_running = GNUNET_YES;
1756 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1757 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
1758 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1759 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
1760 reply->host_id = htonl (GST_context->host_id);
1761 reply->peer_id = msg->peer_id;
1762 reply->operation_id = msg->operation_id;
1763 GST_queue_message (client, &reply->header);
1764 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1769 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1772 * @param client identification of the client
1773 * @param message the actual message
1776 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
1777 const struct GNUNET_MessageHeader *message)
1779 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1780 struct GNUNET_TESTBED_PeerEventMessage *reply;
1781 struct ForwardedOperationContext *fopc;
1785 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
1786 peer_id = ntohl (msg->peer_id);
1787 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PEER_STOP for peer %u\n", peer_id);
1788 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1790 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1792 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1795 peer = GST_peer_list[peer_id];
1796 if (GNUNET_YES == peer->is_remote)
1798 LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarding PEER_STOP for peer %u\n",
1800 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1801 GNUNET_SERVER_client_keep (client);
1802 fopc->client = client;
1803 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1804 fopc->type = OP_PEER_STOP;
1806 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1808 fopc->operation_id, &msg->header,
1809 &GST_forwarded_operation_reply_relay,
1811 fopc->timeout_task =
1812 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1814 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1815 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1818 if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer))
1820 LOG (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %u failed\n", peer_id);
1821 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1822 "Peer not running");
1823 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1826 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %u successfully stopped\n", peer_id);
1827 peer->details.local.is_running = GNUNET_NO;
1828 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1829 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
1830 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1831 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
1832 reply->host_id = htonl (GST_context->host_id);
1833 reply->peer_id = msg->peer_id;
1834 reply->operation_id = msg->operation_id;
1835 GST_queue_message (client, &reply->header);
1836 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1837 GNUNET_TESTING_peer_wait (peer->details.local.peer);
1842 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
1845 * @param client identification of the client
1846 * @param message the actual message
1849 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1850 const struct GNUNET_MessageHeader *message)
1852 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
1853 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
1862 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
1863 peer_id = ntohl (msg->peer_id);
1864 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1866 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1868 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1871 peer = GST_peer_list[peer_id];
1872 if (GNUNET_YES == peer->is_remote)
1874 struct ForwardedOperationContext *fopc;
1876 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", peer_id);
1877 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1878 GNUNET_SERVER_client_keep (client);
1879 fopc->client = client;
1880 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1881 fopc->type = OP_PEER_INFO;
1883 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1885 fopc->operation_id, &msg->header,
1886 &GST_forwarded_operation_reply_relay,
1888 fopc->timeout_task =
1889 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1891 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1892 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1895 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", peer_id);
1897 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg,
1899 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
1900 GNUNET_free (config);
1903 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1904 reply = GNUNET_realloc (xconfig, msize);
1905 (void) memmove (&reply[1], reply, xc_size);
1906 reply->header.size = htons (msize);
1907 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION);
1908 reply->peer_id = msg->peer_id;
1909 reply->operation_id = msg->operation_id;
1910 GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer,
1911 &reply->peer_identity);
1912 reply->config_size = htons ((uint16_t) c_size);
1913 GST_queue_message (client, &reply->header);
1914 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1919 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
1922 * @param client identification of the client
1923 * @param message the actual message
1926 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1927 const struct GNUNET_MessageHeader *message)
1929 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
1930 struct Slave *slave;
1931 struct GNUNET_TESTBED_SlaveConfiguration *reply;
1932 const struct GNUNET_CONFIGURATION_Handle *cfg;
1936 size_t xconfig_size;
1941 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
1942 slave_id = ntohl (msg->slave_id);
1943 op_id = GNUNET_ntohll (msg->operation_id);
1944 if ((GST_slave_list_size <= slave_id) || (NULL == GST_slave_list[slave_id]))
1946 /* FIXME: Add forwardings for this type of message here.. */
1947 GST_send_operation_fail_msg (client, op_id, "Slave not found");
1948 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1951 slave = GST_slave_list[slave_id];
1952 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (GST_host_list[slave->host_id])));
1953 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
1955 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
1956 GNUNET_free (config);
1957 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
1958 GNUNET_break (reply_size <= UINT16_MAX);
1959 GNUNET_break (config_size <= UINT16_MAX);
1960 reply = GNUNET_realloc (xconfig, reply_size);
1961 (void) memmove (&reply[1], reply, xconfig_size);
1962 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION);
1963 reply->header.size = htons ((uint16_t) reply_size);
1964 reply->slave_id = msg->slave_id;
1965 reply->operation_id = msg->operation_id;
1966 reply->config_size = htons ((uint16_t) config_size);
1967 GST_queue_message (client, &reply->header);
1968 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1973 * Iterator over hash map entries.
1975 * @param cls closure
1976 * @param key current key code
1977 * @param value value in the hash map
1978 * @return GNUNET_YES if we should continue to
1983 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1985 struct SharedService *ss = value;
1987 GNUNET_assert (GNUNET_YES ==
1988 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
1989 GNUNET_free (ss->name);
1996 * Iterator for freeing hash map entries in a slave's reghost_map
1998 * @param cls handle to the slave
1999 * @param key current key code
2000 * @param value value in the hash map
2001 * @return GNUNET_YES if we should continue to
2006 reghost_free_iterator (void *cls, const struct GNUNET_HashCode *key,
2009 struct Slave *slave = cls;
2010 struct RegisteredHostContext *rhc = value;
2011 struct ForwardedOverlayConnectContext *focc;
2013 GNUNET_assert (GNUNET_YES ==
2014 GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key,
2016 while (NULL != (focc = rhc->focc_dll_head))
2018 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc);
2019 GST_cleanup_focc (focc);
2021 if (NULL != rhc->sub_op)
2022 GNUNET_TESTBED_operation_done (rhc->sub_op);
2023 if (NULL != rhc->client)
2024 GNUNET_SERVER_client_drop (rhc->client);
2025 GNUNET_free (value);
2031 * Task to clean up and shutdown nicely
2034 * @param tc the TaskContext from scheduler
2037 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2039 struct LCFContextQueue *lcfq;
2040 struct ForwardedOperationContext *fopc;
2041 struct MessageQueue *mq_entry;
2044 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
2045 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
2046 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
2048 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
2049 /* cleanup any remaining forwarded operations */
2050 while (NULL != (fopc = fopcq_head))
2052 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
2053 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
2054 if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
2055 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
2056 GNUNET_SERVER_client_drop (fopc->client);
2059 case OP_PEER_CREATE:
2060 GNUNET_free (fopc->cls);
2064 case OP_PEER_DESTROY:
2066 case OP_OVERLAY_CONNECT:
2067 case OP_LINK_CONTROLLERS:
2068 case OP_GET_SLAVE_CONFIG:
2075 if (NULL != lcfq_head)
2077 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
2079 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
2080 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
2083 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
2084 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
2086 GNUNET_SERVER_client_drop (lcfq->lcf->client);
2087 GNUNET_assert (NULL != lcfq->lcf->cfg);
2088 GNUNET_CONFIGURATION_destroy (lcfq->lcf->cfg);
2089 GNUNET_free (lcfq->lcf);
2090 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
2095 /* Clear peer list */
2096 for (id = 0; id < GST_peer_list_size; id++)
2097 if (NULL != GST_peer_list[id])
2099 /* If destroy flag is set it means that this peer should have been
2100 * destroyed by a context which we destroy before */
2101 GNUNET_break (GNUNET_NO == GST_peer_list[id]->destroy_flag);
2102 /* counter should be zero as we free all contexts before */
2103 GNUNET_break (0 == GST_peer_list[id]->reference_cnt);
2104 if ((GNUNET_NO == GST_peer_list[id]->is_remote) &&
2105 (GNUNET_YES == GST_peer_list[id]->details.local.is_running))
2106 GNUNET_TESTING_peer_kill (GST_peer_list[id]->details.local.peer);
2108 for (id = 0; id < GST_peer_list_size; id++)
2109 if (NULL != GST_peer_list[id])
2111 if (GNUNET_NO == GST_peer_list[id]->is_remote)
2113 if (GNUNET_YES == GST_peer_list[id]->details.local.is_running)
2114 GNUNET_TESTING_peer_wait (GST_peer_list[id]->details.local.peer);
2115 GNUNET_TESTING_peer_destroy (GST_peer_list[id]->details.local.peer);
2116 GNUNET_CONFIGURATION_destroy (GST_peer_list[id]->details.local.cfg);
2118 GNUNET_free (GST_peer_list[id]);
2120 GNUNET_free_non_null (GST_peer_list);
2121 /* Clear host list */
2122 for (id = 0; id < GST_host_list_size; id++)
2123 if (NULL != GST_host_list[id])
2124 GNUNET_TESTBED_host_destroy (GST_host_list[id]);
2125 GNUNET_free_non_null (GST_host_list);
2126 /* Clear route list */
2127 for (id = 0; id < route_list_size; id++)
2128 if (NULL != route_list[id])
2129 GNUNET_free (route_list[id]);
2130 GNUNET_free_non_null (route_list);
2131 /* Clear GST_slave_list */
2132 for (id = 0; id < GST_slave_list_size; id++)
2133 if (NULL != GST_slave_list[id])
2135 struct HostRegistration *hr_entry;
2137 while (NULL != (hr_entry = GST_slave_list[id]->hr_dll_head))
2139 GNUNET_CONTAINER_DLL_remove (GST_slave_list[id]->hr_dll_head,
2140 GST_slave_list[id]->hr_dll_tail, hr_entry);
2141 GNUNET_free (hr_entry);
2143 if (NULL != GST_slave_list[id]->rhandle)
2144 GNUNET_TESTBED_cancel_registration (GST_slave_list[id]->rhandle);
2146 GNUNET_CONTAINER_multihashmap_iterate (GST_slave_list
2148 reghost_free_iterator,
2149 GST_slave_list[id]);
2150 GNUNET_CONTAINER_multihashmap_destroy (GST_slave_list[id]->reghost_map);
2151 if (NULL != GST_slave_list[id]->controller)
2152 GNUNET_TESTBED_controller_disconnect (GST_slave_list[id]->controller);
2153 if (NULL != GST_slave_list[id]->controller_proc)
2154 GNUNET_TESTBED_controller_stop (GST_slave_list[id]->controller_proc);
2155 GNUNET_free (GST_slave_list[id]);
2157 GNUNET_free_non_null (GST_slave_list);
2158 if (NULL != GST_context)
2160 GNUNET_free_non_null (GST_context->master_ip);
2161 if (NULL != GST_context->system)
2162 GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
2163 GNUNET_SERVER_client_drop (GST_context->client);
2164 GNUNET_free (GST_context);
2167 if (NULL != transmit_handle)
2168 GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle);
2169 while (NULL != (mq_entry = mq_head))
2171 GNUNET_free (mq_entry->msg);
2172 GNUNET_SERVER_client_drop (mq_entry->client);
2173 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
2174 GNUNET_free (mq_entry);
2176 GNUNET_free_non_null (hostname);
2177 GNUNET_CONFIGURATION_destroy (our_config);
2178 /* Free hello cache */
2180 GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
2181 GST_opq_openfds = NULL;
2186 * Callback for client disconnect
2189 * @param client the client which has disconnected
2192 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
2194 if (NULL == GST_context)
2196 if (client == GST_context->client)
2198 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
2199 /* should not be needed as we're terminated by failure to read
2200 * from stdin, but if stdin fails for some reason, this shouldn't
2201 * hurt for now --- might need to revise this later if we ever
2202 * decide that master connections might be temporarily down
2203 * for some reason */
2204 //GNUNET_SCHEDULER_shutdown ();
2212 * @param cls closure
2213 * @param server the initialized server
2214 * @param cfg configuration to use
2217 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
2218 const struct GNUNET_CONFIGURATION_Handle *cfg)
2220 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
2221 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
2222 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
2223 {&handle_configure_shared_service, NULL,
2224 GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE, 0},
2225 {&handle_link_controllers, NULL,
2226 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, 0},
2227 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, 0},
2228 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER,
2229 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
2230 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER,
2231 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
2232 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER,
2233 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
2234 {&handle_peer_get_config, NULL,
2235 GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION,
2236 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
2237 {&GST_handle_overlay_connect, NULL,
2238 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT,
2239 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
2240 {&GST_handle_remote_overlay_connect, NULL,
2241 GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, 0},
2242 {handle_slave_get_config, NULL,
2243 GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION,
2244 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
2248 unsigned long long num;
2251 GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
2254 GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile));
2255 GNUNET_free (logfile);
2257 GNUNET_assert (GNUNET_OK ==
2258 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2259 "CACHE_SIZE", &num));
2260 GST_cache_init ((unsigned int) num);
2261 GNUNET_assert (GNUNET_OK ==
2262 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2263 "MAX_OPEN_FDS", &num));
2264 GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ ((unsigned int) num);
2265 GNUNET_assert (GNUNET_OK ==
2266 GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
2267 "OPERATION_TIMEOUT",
2269 GNUNET_TIME_Relative *)
2271 GNUNET_assert (GNUNET_OK ==
2272 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
2273 "HOSTNAME", &hostname));
2274 our_config = GNUNET_CONFIGURATION_dup (cfg);
2275 GNUNET_SERVER_add_handlers (server, message_handlers);
2276 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
2277 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
2279 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
2280 GNUNET_SCHEDULER_PRIORITY_IDLE,
2281 &shutdown_task, NULL);
2282 LOG_DEBUG ("Testbed startup complete\n");
2283 event_mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
2288 * The starting point of execution
2291 main (int argc, char *const *argv)
2293 //sleep (15); /* Debugging */
2294 return (GNUNET_OK ==
2295 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
2296 &testbed_run, NULL)) ? 0 : 1;
2299 /* end of gnunet-service-testbed.c */