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_DEBUG, "A forwarded operation has timed out\n");
712 GST_send_operation_fail_msg (fopc->client, fopc->operation_id,
713 "A forwarded operation has timed out");
714 GNUNET_SERVER_client_drop (fopc->client);
715 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
721 * The Link Controller forwarding task
723 * @param cls the LCFContext
724 * @param tc the Task context from scheduler
727 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
731 * Task to free resources when forwarded link controllers has been timedout
733 * @param cls the LCFContext
734 * @param tc the task context from scheduler
737 lcf_forwarded_operation_timeout (void *cls,
738 const struct GNUNET_SCHEDULER_TaskContext *tc)
740 struct LCFContext *lcf = cls;
742 lcf->timeout_task = GNUNET_SCHEDULER_NO_TASK;
743 // GST_forwarded_operation_timeout (lcf->fopc, tc);
744 LOG (GNUNET_ERROR_TYPE_WARNING,
745 "A forwarded controller link operation has timed out\n");
746 send_controller_link_response (lcf->client, lcf->operation_id, NULL,
747 "A forwarded controller link operation has "
749 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
750 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
755 * The Link Controller forwarding task
757 * @param cls the LCFContext
758 * @param tc the Task context from scheduler
761 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
763 struct LCFContext *lcf = cls;
764 struct LCFContextQueue *lcfq;
766 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
771 GNUNET_TESTBED_is_host_registered_ (GST_host_list
772 [lcf->delegated_host_id],
773 lcf->gateway->controller))
775 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
776 GST_host_list[lcf->delegated_host_id]);
780 lcf->state = DELEGATED_HOST_REGISTERED;
781 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
784 case DELEGATED_HOST_REGISTERED:
786 GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id],
787 lcf->gateway->controller))
789 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
790 GST_host_list[lcf->slave_host_id]);
794 lcf->state = SLAVE_HOST_REGISTERED;
795 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
798 case SLAVE_HOST_REGISTERED:
799 lcf->op = GNUNET_TESTBED_controller_link (lcf,
800 lcf->gateway->controller,
801 GST_host_list[lcf->delegated_host_id],
802 GST_host_list[lcf->slave_host_id],
804 lcf->is_subordinate);
806 GNUNET_SCHEDULER_add_delayed (GST_timeout, &lcf_forwarded_operation_timeout,
808 lcf->state = FINISHED;
812 GNUNET_assert (lcfq->lcf == lcf);
813 GNUNET_assert (NULL != lcf->cfg);
814 GNUNET_CONFIGURATION_destroy (lcf->cfg);
815 GNUNET_SERVER_client_drop (lcf->client);
816 GNUNET_TESTBED_operation_done (lcf->op);
818 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
820 if (NULL != lcfq_head)
822 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
828 * Callback for event from slave controllers
830 * @param cls struct Slave *
831 * @param event information about the event
834 slave_event_callback (void *cls,
835 const struct GNUNET_TESTBED_EventInformation *event)
837 struct RegisteredHostContext *rhc;
838 struct LCFContext *lcf;
839 struct GNUNET_CONFIGURATION_Handle *cfg;
840 struct GNUNET_TESTBED_Operation *old_op;
842 /* We currently only get here when working on RegisteredHostContexts and
844 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
845 rhc = event->details.operation_finished.op_cls;
846 if (CLOSURE_TYPE_RHC == rhc->type)
848 GNUNET_assert (rhc->sub_op == event->details.operation_finished.operation);
852 cfg = event->details.operation_finished.generic;
853 old_op = rhc->sub_op;
854 rhc->state = RHC_LINK;
856 GNUNET_TESTBED_controller_link (rhc, rhc->gateway->controller,
857 rhc->reg_host, rhc->host, cfg,
859 GNUNET_TESTBED_operation_done (old_op);
862 LOG_DEBUG ("OL: Linking controllers successfull\n");
863 GNUNET_TESTBED_operation_done (rhc->sub_op);
865 rhc->state = RHC_OL_CONNECT;
866 GST_process_next_focc (rhc);
873 lcf = event->details.operation_finished.op_cls;
874 if (CLOSURE_TYPE_LCF == lcf->type)
876 GNUNET_assert (lcf->op == event->details.operation_finished.operation);
877 GNUNET_assert (FINISHED == lcf->state);
878 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != lcf->timeout_task);
879 GNUNET_SCHEDULER_cancel (lcf->timeout_task);
880 if (NULL == event->details.operation_finished.emsg)
881 send_controller_link_response (lcf->client, lcf->operation_id,
882 GNUNET_TESTBED_host_get_cfg_
883 (GST_host_list[lcf->delegated_host_id]),
886 send_controller_link_response (lcf->client, lcf->operation_id,
888 event->details.operation_finished.emsg);
889 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
890 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
898 * Callback to signal successfull startup of the controller process
900 * @param cls the handle to the slave whose status is to be found here
901 * @param cfg the configuration with which the controller has been started;
902 * NULL if status is not GNUNET_OK
903 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
904 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
907 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
910 struct Slave *slave = cls;
911 struct LinkControllersContext *lcc;
914 if (GNUNET_SYSERR == status)
916 slave->controller_proc = NULL;
917 GST_slave_list[slave->host_id] = NULL;
920 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
921 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
925 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
926 event_mask, &slave_event_callback,
928 if (NULL != slave->controller)
930 send_controller_link_response (lcc->client, lcc->operation_id, cfg, NULL);
934 send_controller_link_response (lcc->client, lcc->operation_id, NULL,
935 "Could not connect to delegated controller");
936 GNUNET_TESTBED_controller_stop (slave->controller_proc);
937 GST_slave_list[slave->host_id] = NULL;
945 if (NULL != lcc->client)
947 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
948 GNUNET_SERVER_client_drop (lcc->client);
959 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
962 * @param client identification of the client
963 * @param message the actual message
966 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
967 const struct GNUNET_MessageHeader *message)
969 const struct GNUNET_TESTBED_InitMessage *msg;
970 struct GNUNET_TESTBED_Host *host;
971 const char *controller_hostname;
974 if (NULL != GST_context)
976 LOG_DEBUG ("We are being connected to laterally\n");
977 GNUNET_SERVER_receive_done (client, GNUNET_OK);
980 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
981 msize = ntohs (message->size);
982 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
985 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
988 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
989 controller_hostname = (const char *) &msg[1];
990 if ('\0' != controller_hostname[msize - 1])
993 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
996 GST_context = GNUNET_malloc (sizeof (struct Context));
997 GNUNET_SERVER_client_keep (client);
998 GST_context->client = client;
999 GST_context->host_id = ntohl (msg->host_id);
1000 GST_context->master_ip = GNUNET_strdup (controller_hostname);
1001 LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
1002 GST_context->system =
1003 GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
1006 GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
1007 GST_context->master_ip, NULL,
1009 host_list_add (host);
1010 LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id);
1011 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1016 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1019 * @param client identification of the client
1020 * @param message the actual message
1023 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
1024 const struct GNUNET_MessageHeader *message)
1026 struct GNUNET_TESTBED_Host *host;
1027 const struct GNUNET_TESTBED_AddHostMessage *msg;
1028 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
1029 struct GNUNET_CONFIGURATION_Handle *host_cfg;
1035 uint16_t username_length;
1036 uint16_t hostname_length;
1037 uint16_t reply_size;
1040 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
1041 msize = ntohs (msg->header.size);
1042 if (msize <= sizeof (struct GNUNET_TESTBED_AddHostMessage))
1044 GNUNET_break_op (0);
1045 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1048 username_length = ntohs (msg->username_length);
1049 hostname_length = ntohs (msg->hostname_length);
1050 /* msg must contain hostname */
1051 if ((msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
1053 || (0 == hostname_length))
1055 GNUNET_break_op (0);
1056 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1059 /* msg must contain configuration */
1060 if (msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
1061 username_length + hostname_length))
1063 GNUNET_break_op (0);
1064 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1070 if (0 != username_length)
1072 username = GNUNET_malloc (username_length + 1);
1073 strncpy (username, ptr, username_length);
1074 ptr += username_length;
1076 hostname = GNUNET_malloc (hostname_length + 1);
1077 strncpy (hostname, ptr, hostname_length);
1078 ptr += hostname_length;
1079 if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (message)))
1081 GNUNET_free_non_null (username);
1082 GNUNET_free_non_null (hostname);
1083 GNUNET_break_op (0);
1084 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1087 host_id = ntohl (msg->host_id);
1088 LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
1089 LOG_DEBUG ("-------host id: %u\n", host_id);
1090 LOG_DEBUG ("-------hostname: %s\n", hostname);
1091 if (NULL != username)
1092 LOG_DEBUG ("-------username: %s\n", username);
1094 LOG_DEBUG ("-------username: <not given>\n");
1095 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1097 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1098 host_cfg, ntohs (msg->ssh_port));
1099 GNUNET_free_non_null (username);
1100 GNUNET_free (hostname);
1101 GNUNET_CONFIGURATION_destroy (host_cfg);
1104 GNUNET_break_op (0);
1105 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1108 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1109 if (GNUNET_OK != host_list_add (host))
1111 /* We are unable to add a host */
1112 emsg = "A host exists with given host-id";
1113 LOG_DEBUG ("%s: %u", emsg, host_id);
1114 GNUNET_TESTBED_host_destroy (host);
1115 reply_size += strlen (emsg) + 1;
1116 reply = GNUNET_malloc (reply_size);
1117 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1121 LOG_DEBUG ("Added host %u at %u\n", host_id, GST_context->host_id);
1122 reply = GNUNET_malloc (reply_size);
1124 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS);
1125 reply->header.size = htons (reply_size);
1126 reply->host_id = htonl (host_id);
1127 GST_queue_message (client, &reply->header);
1128 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1133 * Iterator over hash map entries.
1135 * @param cls closure
1136 * @param key current key code
1137 * @param value value in the hash map
1138 * @return GNUNET_YES if we should continue to
1143 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1145 struct SharedService *queried_ss = cls;
1146 struct SharedService *ss = value;
1148 if (0 == strcmp (ss->name, queried_ss->name))
1156 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1159 * @param client identification of the client
1160 * @param message the actual message
1163 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1164 const struct GNUNET_MessageHeader *message)
1166 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1167 struct SharedService *ss;
1169 struct GNUNET_HashCode hash;
1171 uint16_t service_name_size;
1173 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1174 msg_size = ntohs (message->size);
1175 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1178 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1182 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1183 service_name = (char *) &msg[1];
1184 if ('\0' != service_name[service_name_size - 1])
1187 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1190 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1191 service_name, ntohl (msg->num_peers));
1192 if (ntohl (msg->host_id) != GST_context->host_id)
1194 route_message (ntohl (msg->host_id), message);
1195 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1198 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1199 ss = GNUNET_malloc (sizeof (struct SharedService));
1200 ss->name = strdup (service_name);
1201 ss->num_shared = ntohl (msg->num_peers);
1202 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1203 if (GNUNET_SYSERR ==
1204 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1205 &ss_exists_iterator, ss))
1207 LOG (GNUNET_ERROR_TYPE_WARNING,
1208 "Service %s already configured as a shared service. "
1209 "Ignoring service sharing request \n", ss->name);
1210 GNUNET_free (ss->name);
1214 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1215 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1220 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1223 * @param client identification of the client
1224 * @param message the actual message
1227 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1228 const struct GNUNET_MessageHeader *message)
1230 const struct GNUNET_TESTBED_ControllerLinkRequest *msg;
1231 struct GNUNET_CONFIGURATION_Handle *cfg;
1232 struct LCFContextQueue *lcfq;
1233 struct Route *route;
1234 struct Route *new_route;
1235 uint32_t delegated_host_id;
1236 uint32_t slave_host_id;
1239 if (NULL == GST_context)
1242 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1245 msize = ntohs (message->size);
1246 if (sizeof (struct GNUNET_TESTBED_ControllerLinkRequest) >= msize)
1249 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1252 msg = (const struct GNUNET_TESTBED_ControllerLinkRequest *) message;
1253 delegated_host_id = ntohl (msg->delegated_host_id);
1254 if (delegated_host_id == GST_context->host_id)
1257 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1258 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1261 if ((delegated_host_id >= GST_host_list_size) ||
1262 (NULL == GST_host_list[delegated_host_id]))
1264 LOG (GNUNET_ERROR_TYPE_WARNING,
1265 "Delegated host %u not registered with us\n", delegated_host_id);
1266 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1269 slave_host_id = ntohl (msg->slave_host_id);
1270 if ((slave_host_id >= GST_host_list_size) ||
1271 (NULL == GST_host_list[slave_host_id]))
1273 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n",
1275 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1278 if (slave_host_id == delegated_host_id)
1280 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1281 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1284 cfg = GNUNET_TESTBED_extract_config_ (message); /* destroy cfg here or in lcfcontext */
1287 GNUNET_break (0); /* Configuration parsing error */
1288 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1291 if (slave_host_id == GST_context->host_id) /* Link from us */
1293 struct Slave *slave;
1294 struct LinkControllersContext *lcc;
1296 if ((delegated_host_id < GST_slave_list_size) &&
1297 (NULL != GST_slave_list[delegated_host_id]))
1300 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1303 slave = GNUNET_malloc (sizeof (struct Slave));
1304 slave->host_id = delegated_host_id;
1305 slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
1306 slave_list_add (slave);
1307 if (1 != msg->is_subordinate)
1310 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
1311 event_mask, &slave_event_callback,
1313 if (NULL != slave->controller)
1314 send_controller_link_response (client,
1315 GNUNET_ntohll (msg->operation_id),
1319 send_controller_link_response (client,
1320 GNUNET_ntohll (msg->operation_id),
1322 "Could not connect to delegated controller");
1323 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1326 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1327 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1328 GNUNET_SERVER_client_keep (client);
1329 lcc->client = client;
1331 slave->controller_proc =
1332 GNUNET_TESTBED_controller_start (GST_context->master_ip,
1333 GST_host_list[slave->host_id], cfg,
1334 &slave_status_callback, slave);
1335 GNUNET_CONFIGURATION_destroy (cfg);
1336 new_route = GNUNET_malloc (sizeof (struct Route));
1337 new_route->dest = delegated_host_id;
1338 new_route->thru = GST_context->host_id;
1339 route_list_add (new_route);
1343 /* Route the request */
1344 if (slave_host_id >= route_list_size)
1346 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1347 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1350 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1351 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1352 lcfq->lcf->type = CLOSURE_TYPE_LCF;
1353 lcfq->lcf->delegated_host_id = delegated_host_id;
1354 lcfq->lcf->slave_host_id = slave_host_id;
1355 route = GST_find_dest_route (slave_host_id);
1356 GNUNET_assert (NULL != route); /* because we add routes carefully */
1357 GNUNET_assert (route->dest < GST_slave_list_size);
1358 GNUNET_assert (NULL != GST_slave_list[route->dest]);
1359 lcfq->lcf->cfg = cfg;
1360 lcfq->lcf->is_subordinate = msg->is_subordinate;
1361 lcfq->lcf->state = INIT;
1362 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1363 lcfq->lcf->gateway = GST_slave_list[route->dest];
1364 GNUNET_SERVER_client_keep (client);
1365 lcfq->lcf->client = client;
1366 if (NULL == lcfq_head)
1368 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1369 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1370 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1373 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1374 /* FIXME: Adding a new route should happen after the controllers are linked
1376 if (1 != msg->is_subordinate)
1378 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1381 if ((delegated_host_id < route_list_size) &&
1382 (NULL != route_list[delegated_host_id]))
1384 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1385 * with is subordinate flag set to GNUNET_YES? */
1386 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1389 new_route = GNUNET_malloc (sizeof (struct Route));
1390 new_route->dest = delegated_host_id;
1391 new_route->thru = route->dest;
1392 route_list_add (new_route);
1393 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1398 * The task to be executed if the forwarded peer create operation has been
1401 * @param cls the FowardedOperationContext
1402 * @param tc the TaskContext from the scheduler
1405 peer_create_forward_timeout (void *cls,
1406 const struct GNUNET_SCHEDULER_TaskContext *tc)
1408 struct ForwardedOperationContext *fopc = cls;
1410 GNUNET_free (fopc->cls);
1411 GST_forwarded_operation_timeout (fopc, tc);
1416 * Callback to be called when forwarded peer create operation is successfull. We
1417 * have to relay the reply msg back to the client
1419 * @param cls ForwardedOperationContext
1420 * @param msg the peer create success message
1423 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1425 struct ForwardedOperationContext *fopc = cls;
1426 struct Peer *remote_peer;
1428 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS)
1430 GNUNET_assert (NULL != fopc->cls);
1431 remote_peer = fopc->cls;
1432 peer_list_add (remote_peer);
1434 GST_forwarded_operation_reply_relay (fopc, msg);
1439 * Function to destroy a peer
1441 * @param peer the peer structure to destroy
1444 GST_destroy_peer (struct Peer *peer)
1446 GNUNET_break (0 == peer->reference_cnt);
1447 if (GNUNET_YES == peer->is_remote)
1449 peer_list_remove (peer);
1453 if (GNUNET_YES == peer->details.local.is_running)
1455 GNUNET_TESTING_peer_stop (peer->details.local.peer);
1456 peer->details.local.is_running = GNUNET_NO;
1458 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1459 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
1460 peer_list_remove (peer);
1466 * Callback to be called when forwarded peer destroy operation is successfull. We
1467 * have to relay the reply msg back to the client
1469 * @param cls ForwardedOperationContext
1470 * @param msg the peer create success message
1473 peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1475 struct ForwardedOperationContext *fopc = cls;
1476 struct Peer *remote_peer;
1478 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS ==
1481 remote_peer = fopc->cls;
1482 GNUNET_assert (NULL != remote_peer);
1483 remote_peer->destroy_flag = GNUNET_YES;
1484 if (0 == remote_peer->reference_cnt)
1485 GST_destroy_peer (remote_peer);
1487 GST_forwarded_operation_reply_relay (fopc, msg);
1493 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1496 * @param client identification of the client
1497 * @param message the actual message
1500 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1501 const struct GNUNET_MessageHeader *message)
1503 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1504 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1505 struct GNUNET_CONFIGURATION_Handle *cfg;
1506 struct ForwardedOperationContext *fo_ctxt;
1507 struct Route *route;
1512 uint32_t config_size;
1518 msize = ntohs (message->size);
1519 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1521 GNUNET_break (0); /* We need configuration */
1522 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1525 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1526 host_id = ntohl (msg->host_id);
1527 peer_id = ntohl (msg->peer_id);
1528 if (UINT32_MAX == peer_id)
1530 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1531 "Cannot create peer with given ID");
1532 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1535 if (host_id == GST_context->host_id)
1539 /* We are responsible for this peer */
1540 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1541 config_size = ntohl (msg->config_size);
1542 config = GNUNET_malloc (config_size);
1543 dest_size = config_size;
1546 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1547 (const Bytef *) &msg[1], (uLong) msize)))
1549 GNUNET_break (0); /* uncompression error */
1550 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1553 if (config_size != dest_size)
1555 GNUNET_break (0); /* Uncompressed config size mismatch */
1556 GNUNET_free (config);
1557 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1560 cfg = GNUNET_CONFIGURATION_create ();
1562 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1564 GNUNET_break (0); /* Configuration parsing error */
1565 GNUNET_free (config);
1566 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1569 GNUNET_free (config);
1570 GNUNET_CONFIGURATION_set_value_number (cfg, "TESTBED", "PEERID",
1571 (unsigned long long) peer_id);
1572 peer = GNUNET_malloc (sizeof (struct Peer));
1573 peer->is_remote = GNUNET_NO;
1574 peer->details.local.cfg = cfg;
1576 LOG_DEBUG ("Creating peer with id: %u\n", (unsigned int) peer->id);
1577 peer->details.local.peer =
1578 GNUNET_TESTING_peer_configure (GST_context->system,
1579 peer->details.local.cfg, peer->id,
1580 NULL /* Peer id */ ,
1582 if (NULL == peer->details.local.peer)
1584 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1588 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1591 peer->details.local.is_running = GNUNET_NO;
1592 peer_list_add (peer);
1594 GNUNET_malloc (sizeof
1595 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1596 reply->header.size =
1597 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1598 reply->header.type =
1599 htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS);
1600 reply->peer_id = msg->peer_id;
1601 reply->operation_id = msg->operation_id;
1602 GST_queue_message (client, &reply->header);
1603 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1607 /* Forward peer create request */
1608 route = GST_find_dest_route (host_id);
1612 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1616 peer = GNUNET_malloc (sizeof (struct Peer));
1617 peer->is_remote = GNUNET_YES;
1619 peer->details.remote.slave = GST_slave_list[route->dest];
1620 peer->details.remote.remote_host_id = host_id;
1621 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1622 GNUNET_SERVER_client_keep (client);
1623 fo_ctxt->client = client;
1624 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1625 fo_ctxt->cls = peer; //GST_slave_list[route->dest]->controller;
1626 fo_ctxt->type = OP_PEER_CREATE;
1628 GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list
1629 [route->dest]->controller,
1630 fo_ctxt->operation_id,
1632 peer_create_success_cb, fo_ctxt);
1633 fo_ctxt->timeout_task =
1634 GNUNET_SCHEDULER_add_delayed (GST_timeout, &peer_create_forward_timeout,
1636 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
1637 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1642 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1645 * @param client identification of the client
1646 * @param message the actual message
1649 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
1650 const struct GNUNET_MessageHeader *message)
1652 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1653 struct ForwardedOperationContext *fopc;
1657 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1658 peer_id = ntohl (msg->peer_id);
1659 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1660 peer_id, GNUNET_ntohll (msg->operation_id));
1661 if ((GST_peer_list_size <= peer_id) || (NULL == GST_peer_list[peer_id]))
1663 LOG (GNUNET_ERROR_TYPE_ERROR,
1664 "Asked to destroy a non existent peer with id: %u\n", peer_id);
1665 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1666 "Peer doesn't exist");
1667 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1670 peer = GST_peer_list[peer_id];
1671 if (GNUNET_YES == peer->is_remote)
1673 /* Forward the destory message to sub controller */
1674 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1675 GNUNET_SERVER_client_keep (client);
1676 fopc->client = client;
1678 fopc->type = OP_PEER_DESTROY;
1679 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1681 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1683 fopc->operation_id, &msg->header,
1684 &peer_destroy_success_cb, fopc);
1685 fopc->timeout_task =
1686 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1688 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1689 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1692 peer->destroy_flag = GNUNET_YES;
1693 if (0 == peer->reference_cnt)
1694 GST_destroy_peer (peer);
1696 LOG (GNUNET_ERROR_TYPE_DEBUG,
1697 "Delaying peer destroy as peer is currently in use\n");
1698 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1699 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1704 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1707 * @param client identification of the client
1708 * @param message the actual message
1711 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
1712 const struct GNUNET_MessageHeader *message)
1714 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1715 struct GNUNET_TESTBED_PeerEventMessage *reply;
1716 struct ForwardedOperationContext *fopc;
1720 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
1721 peer_id = ntohl (msg->peer_id);
1722 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1725 LOG (GNUNET_ERROR_TYPE_ERROR,
1726 "Asked to start a non existent peer with id: %u\n", peer_id);
1727 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1730 peer = GST_peer_list[peer_id];
1731 if (GNUNET_YES == peer->is_remote)
1733 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1734 GNUNET_SERVER_client_keep (client);
1735 fopc->client = client;
1736 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1737 fopc->type = OP_PEER_START;
1739 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1741 fopc->operation_id, &msg->header,
1742 &GST_forwarded_operation_reply_relay,
1744 fopc->timeout_task =
1745 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1747 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1748 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1751 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
1753 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1755 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1758 peer->details.local.is_running = GNUNET_YES;
1759 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1760 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
1761 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1762 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
1763 reply->host_id = htonl (GST_context->host_id);
1764 reply->peer_id = msg->peer_id;
1765 reply->operation_id = msg->operation_id;
1766 GST_queue_message (client, &reply->header);
1767 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1772 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1775 * @param client identification of the client
1776 * @param message the actual message
1779 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
1780 const struct GNUNET_MessageHeader *message)
1782 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1783 struct GNUNET_TESTBED_PeerEventMessage *reply;
1784 struct ForwardedOperationContext *fopc;
1788 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
1789 peer_id = ntohl (msg->peer_id);
1790 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PEER_STOP for peer %u\n", peer_id);
1791 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1793 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1795 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1798 peer = GST_peer_list[peer_id];
1799 if (GNUNET_YES == peer->is_remote)
1801 LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarding PEER_STOP for peer %u\n",
1803 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1804 GNUNET_SERVER_client_keep (client);
1805 fopc->client = client;
1806 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1807 fopc->type = OP_PEER_STOP;
1809 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1811 fopc->operation_id, &msg->header,
1812 &GST_forwarded_operation_reply_relay,
1814 fopc->timeout_task =
1815 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1817 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1818 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1821 if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer))
1823 LOG (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %u failed\n", peer_id);
1824 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1825 "Peer not running");
1826 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1829 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %u successfully stopped\n", peer_id);
1830 peer->details.local.is_running = GNUNET_NO;
1831 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1832 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
1833 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1834 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
1835 reply->host_id = htonl (GST_context->host_id);
1836 reply->peer_id = msg->peer_id;
1837 reply->operation_id = msg->operation_id;
1838 GST_queue_message (client, &reply->header);
1839 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1840 GNUNET_TESTING_peer_wait (peer->details.local.peer);
1845 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
1848 * @param client identification of the client
1849 * @param message the actual message
1852 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1853 const struct GNUNET_MessageHeader *message)
1855 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
1856 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
1865 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
1866 peer_id = ntohl (msg->peer_id);
1867 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1869 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1871 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1874 peer = GST_peer_list[peer_id];
1875 if (GNUNET_YES == peer->is_remote)
1877 struct ForwardedOperationContext *fopc;
1879 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", peer_id);
1880 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1881 GNUNET_SERVER_client_keep (client);
1882 fopc->client = client;
1883 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1884 fopc->type = OP_PEER_INFO;
1886 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1888 fopc->operation_id, &msg->header,
1889 &GST_forwarded_operation_reply_relay,
1891 fopc->timeout_task =
1892 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1894 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1895 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1898 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", peer_id);
1900 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg,
1902 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
1903 GNUNET_free (config);
1906 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1907 reply = GNUNET_realloc (xconfig, msize);
1908 (void) memmove (&reply[1], reply, xc_size);
1909 reply->header.size = htons (msize);
1910 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION);
1911 reply->peer_id = msg->peer_id;
1912 reply->operation_id = msg->operation_id;
1913 GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer,
1914 &reply->peer_identity);
1915 reply->config_size = htons ((uint16_t) c_size);
1916 GST_queue_message (client, &reply->header);
1917 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1922 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
1925 * @param client identification of the client
1926 * @param message the actual message
1929 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1930 const struct GNUNET_MessageHeader *message)
1932 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
1933 struct Slave *slave;
1934 struct GNUNET_TESTBED_SlaveConfiguration *reply;
1935 const struct GNUNET_CONFIGURATION_Handle *cfg;
1939 size_t xconfig_size;
1944 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
1945 slave_id = ntohl (msg->slave_id);
1946 op_id = GNUNET_ntohll (msg->operation_id);
1947 if ((GST_slave_list_size <= slave_id) || (NULL == GST_slave_list[slave_id]))
1949 /* FIXME: Add forwardings for this type of message here.. */
1950 GST_send_operation_fail_msg (client, op_id, "Slave not found");
1951 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1954 slave = GST_slave_list[slave_id];
1955 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (GST_host_list[slave->host_id])));
1956 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
1958 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
1959 GNUNET_free (config);
1960 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
1961 GNUNET_break (reply_size <= UINT16_MAX);
1962 GNUNET_break (config_size <= UINT16_MAX);
1963 reply = GNUNET_realloc (xconfig, reply_size);
1964 (void) memmove (&reply[1], reply, xconfig_size);
1965 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION);
1966 reply->header.size = htons ((uint16_t) reply_size);
1967 reply->slave_id = msg->slave_id;
1968 reply->operation_id = msg->operation_id;
1969 reply->config_size = htons ((uint16_t) config_size);
1970 GST_queue_message (client, &reply->header);
1971 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1976 * Iterator over hash map entries.
1978 * @param cls closure
1979 * @param key current key code
1980 * @param value value in the hash map
1981 * @return GNUNET_YES if we should continue to
1986 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1988 struct SharedService *ss = value;
1990 GNUNET_assert (GNUNET_YES ==
1991 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
1992 GNUNET_free (ss->name);
1999 * Iterator for freeing hash map entries in a slave's reghost_map
2001 * @param cls handle to the slave
2002 * @param key current key code
2003 * @param value value in the hash map
2004 * @return GNUNET_YES if we should continue to
2009 reghost_free_iterator (void *cls, const struct GNUNET_HashCode *key,
2012 struct Slave *slave = cls;
2013 struct RegisteredHostContext *rhc = value;
2014 struct ForwardedOverlayConnectContext *focc;
2016 GNUNET_assert (GNUNET_YES ==
2017 GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key,
2019 while (NULL != (focc = rhc->focc_dll_head))
2021 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc);
2022 GST_cleanup_focc (focc);
2024 if (NULL != rhc->sub_op)
2025 GNUNET_TESTBED_operation_done (rhc->sub_op);
2026 if (NULL != rhc->client)
2027 GNUNET_SERVER_client_drop (rhc->client);
2028 GNUNET_free (value);
2034 * Task to clean up and shutdown nicely
2037 * @param tc the TaskContext from scheduler
2040 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2042 struct LCFContextQueue *lcfq;
2043 struct ForwardedOperationContext *fopc;
2044 struct MessageQueue *mq_entry;
2047 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
2048 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
2049 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
2051 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
2052 /* cleanup any remaining forwarded operations */
2053 while (NULL != (fopc = fopcq_head))
2055 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
2056 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
2057 if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
2058 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
2059 GNUNET_SERVER_client_drop (fopc->client);
2062 case OP_PEER_CREATE:
2063 GNUNET_free (fopc->cls);
2067 case OP_PEER_DESTROY:
2069 case OP_OVERLAY_CONNECT:
2070 case OP_LINK_CONTROLLERS:
2071 case OP_GET_SLAVE_CONFIG:
2078 if (NULL != lcfq_head)
2080 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
2082 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
2083 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
2086 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
2087 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
2089 GNUNET_SERVER_client_drop (lcfq->lcf->client);
2090 GNUNET_assert (NULL != lcfq->lcf->cfg);
2091 GNUNET_CONFIGURATION_destroy (lcfq->lcf->cfg);
2092 GNUNET_free (lcfq->lcf);
2093 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
2098 /* Clear peer list */
2099 for (id = 0; id < GST_peer_list_size; id++)
2100 if (NULL != GST_peer_list[id])
2102 /* If destroy flag is set it means that this peer should have been
2103 * destroyed by a context which we destroy before */
2104 GNUNET_break (GNUNET_NO == GST_peer_list[id]->destroy_flag);
2105 /* counter should be zero as we free all contexts before */
2106 GNUNET_break (0 == GST_peer_list[id]->reference_cnt);
2107 if ((GNUNET_NO == GST_peer_list[id]->is_remote) &&
2108 (GNUNET_YES == GST_peer_list[id]->details.local.is_running))
2109 GNUNET_TESTING_peer_kill (GST_peer_list[id]->details.local.peer);
2111 for (id = 0; id < GST_peer_list_size; id++)
2112 if (NULL != GST_peer_list[id])
2114 if (GNUNET_NO == GST_peer_list[id]->is_remote)
2116 if (GNUNET_YES == GST_peer_list[id]->details.local.is_running)
2117 GNUNET_TESTING_peer_wait (GST_peer_list[id]->details.local.peer);
2118 GNUNET_TESTING_peer_destroy (GST_peer_list[id]->details.local.peer);
2119 GNUNET_CONFIGURATION_destroy (GST_peer_list[id]->details.local.cfg);
2121 GNUNET_free (GST_peer_list[id]);
2123 GNUNET_free_non_null (GST_peer_list);
2124 /* Clear host list */
2125 for (id = 0; id < GST_host_list_size; id++)
2126 if (NULL != GST_host_list[id])
2127 GNUNET_TESTBED_host_destroy (GST_host_list[id]);
2128 GNUNET_free_non_null (GST_host_list);
2129 /* Clear route list */
2130 for (id = 0; id < route_list_size; id++)
2131 if (NULL != route_list[id])
2132 GNUNET_free (route_list[id]);
2133 GNUNET_free_non_null (route_list);
2134 /* Clear GST_slave_list */
2135 for (id = 0; id < GST_slave_list_size; id++)
2136 if (NULL != GST_slave_list[id])
2138 struct HostRegistration *hr_entry;
2140 while (NULL != (hr_entry = GST_slave_list[id]->hr_dll_head))
2142 GNUNET_CONTAINER_DLL_remove (GST_slave_list[id]->hr_dll_head,
2143 GST_slave_list[id]->hr_dll_tail, hr_entry);
2144 GNUNET_free (hr_entry);
2146 if (NULL != GST_slave_list[id]->rhandle)
2147 GNUNET_TESTBED_cancel_registration (GST_slave_list[id]->rhandle);
2149 GNUNET_CONTAINER_multihashmap_iterate (GST_slave_list
2151 reghost_free_iterator,
2152 GST_slave_list[id]);
2153 GNUNET_CONTAINER_multihashmap_destroy (GST_slave_list[id]->reghost_map);
2154 if (NULL != GST_slave_list[id]->controller)
2155 GNUNET_TESTBED_controller_disconnect (GST_slave_list[id]->controller);
2156 if (NULL != GST_slave_list[id]->controller_proc)
2157 GNUNET_TESTBED_controller_stop (GST_slave_list[id]->controller_proc);
2158 GNUNET_free (GST_slave_list[id]);
2160 GNUNET_free_non_null (GST_slave_list);
2161 if (NULL != GST_context)
2163 GNUNET_free_non_null (GST_context->master_ip);
2164 if (NULL != GST_context->system)
2165 GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
2166 GNUNET_SERVER_client_drop (GST_context->client);
2167 GNUNET_free (GST_context);
2170 if (NULL != transmit_handle)
2171 GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle);
2172 while (NULL != (mq_entry = mq_head))
2174 GNUNET_free (mq_entry->msg);
2175 GNUNET_SERVER_client_drop (mq_entry->client);
2176 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
2177 GNUNET_free (mq_entry);
2179 GNUNET_free_non_null (hostname);
2180 GNUNET_CONFIGURATION_destroy (our_config);
2181 /* Free hello cache */
2183 GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
2184 GST_opq_openfds = NULL;
2189 * Callback for client disconnect
2192 * @param client the client which has disconnected
2195 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
2197 if (NULL == GST_context)
2199 if (client == GST_context->client)
2201 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
2202 /* should not be needed as we're terminated by failure to read
2203 * from stdin, but if stdin fails for some reason, this shouldn't
2204 * hurt for now --- might need to revise this later if we ever
2205 * decide that master connections might be temporarily down
2206 * for some reason */
2207 //GNUNET_SCHEDULER_shutdown ();
2215 * @param cls closure
2216 * @param server the initialized server
2217 * @param cfg configuration to use
2220 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
2221 const struct GNUNET_CONFIGURATION_Handle *cfg)
2223 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
2224 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
2225 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
2226 {&handle_configure_shared_service, NULL,
2227 GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE, 0},
2228 {&handle_link_controllers, NULL,
2229 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, 0},
2230 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, 0},
2231 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER,
2232 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
2233 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER,
2234 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
2235 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER,
2236 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
2237 {&handle_peer_get_config, NULL,
2238 GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION,
2239 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
2240 {&GST_handle_overlay_connect, NULL,
2241 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT,
2242 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
2243 {&GST_handle_remote_overlay_connect, NULL,
2244 GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, 0},
2245 {handle_slave_get_config, NULL,
2246 GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION,
2247 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
2251 unsigned long long num;
2254 GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
2257 GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile));
2258 GNUNET_free (logfile);
2260 GNUNET_assert (GNUNET_OK ==
2261 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2262 "CACHE_SIZE", &num));
2263 GST_cache_init ((unsigned int) num);
2264 GNUNET_assert (GNUNET_OK ==
2265 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2266 "MAX_OPEN_FDS", &num));
2267 GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ ((unsigned int) num);
2268 GNUNET_assert (GNUNET_OK ==
2269 GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
2270 "OPERATION_TIMEOUT",
2272 GNUNET_TIME_Relative *)
2274 GNUNET_assert (GNUNET_OK ==
2275 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
2276 "HOSTNAME", &hostname));
2277 our_config = GNUNET_CONFIGURATION_dup (cfg);
2278 GNUNET_SERVER_add_handlers (server, message_handlers);
2279 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
2280 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
2282 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
2283 GNUNET_SCHEDULER_PRIORITY_IDLE,
2284 &shutdown_task, NULL);
2285 LOG_DEBUG ("Testbed startup complete\n");
2286 event_mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
2291 * The starting point of execution
2294 main (int argc, char *const *argv)
2296 //sleep (15); /* Debugging */
2297 return (GNUNET_OK ==
2298 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
2299 &testbed_run, NULL)) ? 0 : 1;
2302 /* end of gnunet-service-testbed.c */