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 * Callback which will be called to after a host registration succeeded or failed
480 * @param cls the handle to the slave at which the registration is completed
481 * @param emsg the error message; NULL if host registration is successful
484 hr_completion (void *cls, const char *emsg);
488 * Attempts to register the next host in the host registration queue
490 * @param slave the slave controller whose host registration queue is checked
491 * for host registrations
494 register_next_host (struct Slave *slave)
496 struct HostRegistration *hr;
498 hr = slave->hr_dll_head;
499 GNUNET_assert (NULL != hr);
500 GNUNET_assert (NULL == slave->rhandle);
501 LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n",
502 GNUNET_TESTBED_host_get_id_ (hr->host),
503 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
505 GNUNET_TESTBED_register_host (slave->controller, hr->host, hr_completion,
511 * Callback which will be called to after a host registration succeeded or failed
513 * @param cls the handle to the slave at which the registration is completed
514 * @param emsg the error message; NULL if host registration is successful
517 hr_completion (void *cls, const char *emsg)
519 struct Slave *slave = cls;
520 struct HostRegistration *hr;
522 slave->rhandle = NULL;
523 hr = slave->hr_dll_head;
524 GNUNET_assert (NULL != hr);
525 LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u successful\n",
526 GNUNET_TESTBED_host_get_id_ (hr->host),
527 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
528 GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail, hr);
530 hr->cb (hr->cb_cls, emsg);
532 if (NULL != slave->hr_dll_head)
533 register_next_host (slave);
538 * Adds a host registration's request to a slave's registration queue
540 * @param slave the slave controller at which the given host has to be
542 * @param cb the host registration completion callback
543 * @param cb_cls the closure for the host registration completion callback
544 * @param host the host which has to be registered
547 GST_queue_host_registration (struct Slave *slave,
548 GNUNET_TESTBED_HostRegistrationCompletion cb,
549 void *cb_cls, struct GNUNET_TESTBED_Host *host)
551 struct HostRegistration *hr;
554 LOG (GNUNET_ERROR_TYPE_DEBUG,
555 "Queueing host registration for host %u at %u\n",
556 GNUNET_TESTBED_host_get_id_ (host),
557 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
558 hr = GNUNET_malloc (sizeof (struct HostRegistration));
562 call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO;
563 GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head, slave->hr_dll_tail, hr);
564 if (GNUNET_YES == call_register)
565 register_next_host (slave);
570 * The Link Controller forwarding task
572 * @param cls the LCFContext
573 * @param tc the Task context from scheduler
576 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
580 * Completion callback for host registrations while forwarding Link Controller messages
582 * @param cls the LCFContext
583 * @param emsg the error message; NULL if host registration is successful
586 lcf_proc_cc (void *cls, const char *emsg)
588 struct LCFContext *lcf = cls;
590 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
595 goto registration_error;
596 lcf->state = DELEGATED_HOST_REGISTERED;
597 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
599 case DELEGATED_HOST_REGISTERED:
601 goto registration_error;
602 lcf->state = SLAVE_HOST_REGISTERED;
603 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
606 GNUNET_assert (0); /* Shouldn't reach here */
611 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
613 lcf->state = FINISHED;
614 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
619 * Callback to relay the reply msg of a forwarded operation back to the client
621 * @param cls ForwardedOperationContext
622 * @param msg the message to relay
625 GST_forwarded_operation_reply_relay (void *cls,
626 const struct GNUNET_MessageHeader *msg)
628 struct ForwardedOperationContext *fopc = cls;
629 struct GNUNET_MessageHeader *dup_msg;
632 msize = ntohs (msg->size);
633 LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type),
635 dup_msg = GNUNET_copy_message (msg);
636 GST_queue_message (fopc->client, dup_msg);
637 GNUNET_SERVER_client_drop (fopc->client);
638 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
639 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
645 * Task to free resources when forwarded operation has been timedout
647 * @param cls the ForwardedOperationContext
648 * @param tc the task context from scheduler
651 GST_forwarded_operation_timeout (void *cls,
652 const struct GNUNET_SCHEDULER_TaskContext *tc)
654 struct ForwardedOperationContext *fopc = cls;
656 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
657 LOG (GNUNET_ERROR_TYPE_WARNING, "A forwarded operation has timed out\n");
658 GST_send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
659 GNUNET_SERVER_client_drop (fopc->client);
660 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
666 * The Link Controller forwarding task
668 * @param cls the LCFContext
669 * @param tc the Task context from scheduler
672 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
676 * Callback to be called when forwarded link controllers operation is
677 * successfull. We have to relay the reply msg back to the client
679 * @param cls the LCFContext
680 * @param msg the message to relay
683 lcf_forwarded_operation_reply_relay (void *cls,
684 const struct GNUNET_MessageHeader *msg)
686 struct LCFContext *lcf = cls;
688 GNUNET_assert (NULL != lcf->fopc);
689 GST_forwarded_operation_reply_relay (lcf->fopc, msg);
691 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
692 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
697 * Task to free resources when forwarded link controllers has been timedout
699 * @param cls the LCFContext
700 * @param tc the task context from scheduler
703 lcf_forwarded_operation_timeout (void *cls,
704 const struct GNUNET_SCHEDULER_TaskContext *tc)
706 struct LCFContext *lcf = cls;
708 GNUNET_assert (NULL != lcf->fopc);
709 lcf->fopc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
710 GST_forwarded_operation_timeout (lcf->fopc, tc);
712 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
713 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
718 * The Link Controller forwarding task
720 * @param cls the LCFContext
721 * @param tc the Task context from scheduler
724 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
726 struct LCFContext *lcf = cls;
727 struct LCFContextQueue *lcfq;
729 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
734 GNUNET_TESTBED_is_host_registered_ (GST_host_list
735 [lcf->delegated_host_id],
736 lcf->gateway->controller))
738 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
739 GST_host_list[lcf->delegated_host_id]);
743 lcf->state = DELEGATED_HOST_REGISTERED;
744 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
747 case DELEGATED_HOST_REGISTERED:
749 GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id],
750 lcf->gateway->controller))
752 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
753 GST_host_list[lcf->slave_host_id]);
757 lcf->state = SLAVE_HOST_REGISTERED;
758 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
761 case SLAVE_HOST_REGISTERED:
762 lcf->fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
763 lcf->fopc->client = lcf->client;
764 lcf->fopc->operation_id = lcf->operation_id;
765 lcf->fopc->type = OP_LINK_CONTROLLERS;
767 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
770 &lcf_forwarded_operation_reply_relay,
772 lcf->fopc->timeout_task =
773 GNUNET_SCHEDULER_add_delayed (GST_timeout, &lcf_forwarded_operation_timeout,
775 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, lcf->fopc);
776 lcf->state = FINISHED;
780 GNUNET_assert (lcfq->lcf == lcf);
781 GNUNET_free (lcf->msg);
783 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
785 if (NULL != lcfq_head)
787 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
793 * Callback for event from slave controllers
795 * @param cls struct Slave *
796 * @param event information about the event
799 slave_event_callback (void *cls,
800 const struct GNUNET_TESTBED_EventInformation *event)
802 struct RegisteredHostContext *rhc;
803 struct GNUNET_CONFIGURATION_Handle *cfg;
804 struct GNUNET_TESTBED_Operation *old_op;
806 /* We currently only get here when working on RegisteredHostContexts */
807 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
808 rhc = event->details.operation_finished.op_cls;
809 GNUNET_assert (rhc->sub_op == event->details.operation_finished.operation);
813 cfg = event->details.operation_finished.generic;
814 old_op = rhc->sub_op;
815 rhc->state = RHC_LINK;
817 GNUNET_TESTBED_controller_link (rhc, rhc->gateway->controller,
818 rhc->reg_host, rhc->host, cfg,
820 GNUNET_TESTBED_operation_done (old_op);
823 LOG_DEBUG ("OL: Linking controllers successfull\n");
824 GNUNET_TESTBED_operation_done (rhc->sub_op);
826 rhc->state = RHC_OL_CONNECT;
827 GST_process_next_focc (rhc);
836 * Callback to signal successfull startup of the controller process
838 * @param cls the handle to the slave whose status is to be found here
839 * @param cfg the configuration with which the controller has been started;
840 * NULL if status is not GNUNET_OK
841 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
842 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
845 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
848 struct Slave *slave = cls;
849 struct LinkControllersContext *lcc;
852 if (GNUNET_SYSERR == status)
854 slave->controller_proc = NULL;
855 GST_slave_list[slave->host_id] = NULL;
856 if (NULL != slave->cfg)
857 GNUNET_CONFIGURATION_destroy (slave->cfg);
860 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
861 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
865 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
866 event_mask, &slave_event_callback,
868 if (NULL != slave->controller)
870 send_operation_success_msg (lcc->client, lcc->operation_id);
871 slave->cfg = GNUNET_CONFIGURATION_dup (cfg);
875 GST_send_operation_fail_msg (lcc->client, lcc->operation_id,
876 "Could not connect to delegated controller");
877 GNUNET_TESTBED_controller_stop (slave->controller_proc);
878 GST_slave_list[slave->host_id] = NULL;
886 if (NULL != lcc->client)
888 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
889 GNUNET_SERVER_client_drop (lcc->client);
900 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
903 * @param client identification of the client
904 * @param message the actual message
907 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
908 const struct GNUNET_MessageHeader *message)
910 const struct GNUNET_TESTBED_InitMessage *msg;
911 struct GNUNET_TESTBED_Host *host;
912 const char *controller_hostname;
915 if (NULL != GST_context)
917 LOG_DEBUG ("We are being connected to laterally\n");
918 GNUNET_SERVER_receive_done (client, GNUNET_OK);
921 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
922 msize = ntohs (message->size);
923 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
926 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
929 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
930 controller_hostname = (const char *) &msg[1];
931 if ('\0' != controller_hostname[msize - 1])
934 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
937 GST_context = GNUNET_malloc (sizeof (struct Context));
938 GNUNET_SERVER_client_keep (client);
939 GST_context->client = client;
940 GST_context->host_id = ntohl (msg->host_id);
941 GST_context->master_ip = GNUNET_strdup (controller_hostname);
942 LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
943 GST_context->system =
944 GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
947 GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
948 GST_context->master_ip, NULL,
950 host_list_add (host);
951 LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id);
952 GNUNET_SERVER_receive_done (client, GNUNET_OK);
957 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
960 * @param client identification of the client
961 * @param message the actual message
964 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
965 const struct GNUNET_MessageHeader *message)
967 struct GNUNET_TESTBED_Host *host;
968 const struct GNUNET_TESTBED_AddHostMessage *msg;
969 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
974 uint16_t username_length;
975 uint16_t hostname_length;
979 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
980 msize = ntohs (msg->header.size);
981 username = (char *) &msg[1];
982 username_length = ntohs (msg->user_name_length);
983 if (0 != username_length)
985 /* msg must contain hostname */
986 GNUNET_assert (msize >
987 (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
988 username_length + 1));
989 if (0 != username_length)
990 GNUNET_assert ('\0' == username[username_length - 1]);
991 hostname = username + username_length;
993 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
994 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
995 GNUNET_assert (strlen (hostname) == hostname_length - 1);
996 host_id = ntohl (msg->host_id);
997 LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
998 LOG_DEBUG ("-------host id: %u\n", host_id);
999 LOG_DEBUG ("-------hostname: %s\n", hostname);
1000 if (0 != username_length)
1001 LOG_DEBUG ("-------username: %s\n", username);
1004 LOG_DEBUG ("-------username: NULL\n");
1007 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1008 /* FIXME: should use configuration from ADDHOST message */
1010 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1011 our_config, ntohs (msg->ssh_port));
1012 GNUNET_assert (NULL != host);
1013 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1014 if (GNUNET_OK != host_list_add (host))
1016 /* We are unable to add a host */
1017 emsg = "A host exists with given host-id";
1018 LOG_DEBUG ("%s: %u", emsg, host_id);
1019 GNUNET_TESTBED_host_destroy (host);
1020 reply_size += strlen (emsg) + 1;
1021 reply = GNUNET_malloc (reply_size);
1022 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1026 LOG_DEBUG ("Added host %u at %u\n", host_id, GST_context->host_id);
1027 reply = GNUNET_malloc (reply_size);
1029 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS);
1030 reply->header.size = htons (reply_size);
1031 reply->host_id = htonl (host_id);
1032 GST_queue_message (client, &reply->header);
1033 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1038 * Iterator over hash map entries.
1040 * @param cls closure
1041 * @param key current key code
1042 * @param value value in the hash map
1043 * @return GNUNET_YES if we should continue to
1048 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1050 struct SharedService *queried_ss = cls;
1051 struct SharedService *ss = value;
1053 if (0 == strcmp (ss->name, queried_ss->name))
1061 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1064 * @param client identification of the client
1065 * @param message the actual message
1068 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1069 const struct GNUNET_MessageHeader *message)
1071 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1072 struct SharedService *ss;
1074 struct GNUNET_HashCode hash;
1076 uint16_t service_name_size;
1078 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1079 msg_size = ntohs (message->size);
1080 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1083 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1087 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1088 service_name = (char *) &msg[1];
1089 if ('\0' != service_name[service_name_size - 1])
1092 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1095 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1096 service_name, ntohl (msg->num_peers));
1097 if (ntohl (msg->host_id) != GST_context->host_id)
1099 route_message (ntohl (msg->host_id), message);
1100 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1103 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1104 ss = GNUNET_malloc (sizeof (struct SharedService));
1105 ss->name = strdup (service_name);
1106 ss->num_shared = ntohl (msg->num_peers);
1107 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1108 if (GNUNET_SYSERR ==
1109 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1110 &ss_exists_iterator, ss))
1112 LOG (GNUNET_ERROR_TYPE_WARNING,
1113 "Service %s already configured as a shared service. "
1114 "Ignoring service sharing request \n", ss->name);
1115 GNUNET_free (ss->name);
1119 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1120 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1125 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1128 * @param client identification of the client
1129 * @param message the actual message
1132 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1133 const struct GNUNET_MessageHeader *message)
1135 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1136 struct GNUNET_CONFIGURATION_Handle *cfg;
1137 struct LCFContextQueue *lcfq;
1138 struct Route *route;
1139 struct Route *new_route;
1143 uint32_t delegated_host_id;
1144 uint32_t slave_host_id;
1147 if (NULL == GST_context)
1150 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1153 msize = ntohs (message->size);
1154 if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
1157 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1160 msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
1161 delegated_host_id = ntohl (msg->delegated_host_id);
1162 if (delegated_host_id == GST_context->host_id)
1165 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1166 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1169 if ((delegated_host_id >= GST_host_list_size) ||
1170 (NULL == GST_host_list[delegated_host_id]))
1172 LOG (GNUNET_ERROR_TYPE_WARNING,
1173 "Delegated host %u not registered with us\n", delegated_host_id);
1174 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1177 slave_host_id = ntohl (msg->slave_host_id);
1178 if ((slave_host_id >= GST_host_list_size) ||
1179 (NULL == GST_host_list[slave_host_id]))
1181 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n",
1183 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1186 if (slave_host_id == delegated_host_id)
1188 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1189 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1193 if (slave_host_id == GST_context->host_id) /* Link from us */
1195 struct Slave *slave;
1196 struct LinkControllersContext *lcc;
1198 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1199 config_size = ntohs (msg->config_size);
1200 if ((delegated_host_id < GST_slave_list_size) && (NULL != GST_slave_list[delegated_host_id])) /* We have already added */
1202 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1204 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1207 config = GNUNET_malloc (config_size);
1208 dest_size = (uLongf) config_size;
1210 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1213 GNUNET_break (0); /* Compression error */
1214 GNUNET_free (config);
1215 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1218 if (config_size != dest_size)
1220 LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1221 GNUNET_free (config);
1222 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1225 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1227 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1229 GNUNET_break (0); /* Configuration parsing error */
1230 GNUNET_free (config);
1231 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1234 GNUNET_free (config);
1235 if ((delegated_host_id < GST_slave_list_size) &&
1236 (NULL != GST_slave_list[delegated_host_id]))
1238 GNUNET_break (0); /* Configuration parsing error */
1239 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1242 slave = GNUNET_malloc (sizeof (struct Slave));
1243 slave->host_id = delegated_host_id;
1244 slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
1245 slave_list_add (slave);
1246 if (1 != msg->is_subordinate)
1249 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
1250 event_mask, &slave_event_callback,
1253 if (NULL != slave->controller)
1254 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1256 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1257 "Could not connect to delegated controller");
1258 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1261 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1262 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1263 GNUNET_SERVER_client_keep (client);
1264 lcc->client = client;
1266 slave->controller_proc =
1267 GNUNET_TESTBED_controller_start (GST_context->master_ip,
1268 GST_host_list[slave->host_id], cfg,
1269 &slave_status_callback, slave);
1270 GNUNET_CONFIGURATION_destroy (cfg);
1271 new_route = GNUNET_malloc (sizeof (struct Route));
1272 new_route->dest = delegated_host_id;
1273 new_route->thru = GST_context->host_id;
1274 route_list_add (new_route);
1278 /* Route the request */
1279 if (slave_host_id >= route_list_size)
1281 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1282 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1285 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1286 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1287 lcfq->lcf->delegated_host_id = delegated_host_id;
1288 lcfq->lcf->slave_host_id = slave_host_id;
1289 route = GST_find_dest_route (slave_host_id);
1290 GNUNET_assert (NULL != route); /* because we add routes carefully */
1291 GNUNET_assert (route->dest < GST_slave_list_size);
1292 GNUNET_assert (NULL != GST_slave_list[route->dest]);
1293 lcfq->lcf->state = INIT;
1294 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1295 lcfq->lcf->gateway = GST_slave_list[route->dest];
1296 lcfq->lcf->msg = GNUNET_malloc (msize);
1297 (void) memcpy (lcfq->lcf->msg, msg, msize);
1298 GNUNET_SERVER_client_keep (client);
1299 lcfq->lcf->client = client;
1300 if (NULL == lcfq_head)
1302 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1303 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1304 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1307 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1308 /* FIXME: Adding a new route should happen after the controllers are linked
1310 if (1 != msg->is_subordinate)
1312 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1315 if ((delegated_host_id < route_list_size) &&
1316 (NULL != route_list[delegated_host_id]))
1318 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1319 * with is subordinate flag set to GNUNET_YES? */
1320 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1323 new_route = GNUNET_malloc (sizeof (struct Route));
1324 new_route->dest = delegated_host_id;
1325 new_route->thru = route->dest;
1326 route_list_add (new_route);
1327 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1332 * The task to be executed if the forwarded peer create operation has been
1335 * @param cls the FowardedOperationContext
1336 * @param tc the TaskContext from the scheduler
1339 peer_create_forward_timeout (void *cls,
1340 const struct GNUNET_SCHEDULER_TaskContext *tc)
1342 struct ForwardedOperationContext *fopc = cls;
1344 GNUNET_free (fopc->cls);
1345 GST_forwarded_operation_timeout (fopc, tc);
1350 * Callback to be called when forwarded peer create operation is successfull. We
1351 * have to relay the reply msg back to the client
1353 * @param cls ForwardedOperationContext
1354 * @param msg the peer create success message
1357 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1359 struct ForwardedOperationContext *fopc = cls;
1360 struct Peer *remote_peer;
1362 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS)
1364 GNUNET_assert (NULL != fopc->cls);
1365 remote_peer = fopc->cls;
1366 peer_list_add (remote_peer);
1368 GST_forwarded_operation_reply_relay (fopc, msg);
1373 * Function to destroy a peer
1375 * @param peer the peer structure to destroy
1378 GST_destroy_peer (struct Peer *peer)
1380 GNUNET_break (0 == peer->reference_cnt);
1381 if (GNUNET_YES == peer->is_remote)
1383 peer_list_remove (peer);
1387 if (GNUNET_YES == peer->details.local.is_running)
1389 GNUNET_TESTING_peer_stop (peer->details.local.peer);
1390 peer->details.local.is_running = GNUNET_NO;
1392 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1393 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
1394 peer_list_remove (peer);
1400 * Callback to be called when forwarded peer destroy operation is successfull. We
1401 * have to relay the reply msg back to the client
1403 * @param cls ForwardedOperationContext
1404 * @param msg the peer create success message
1407 peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1409 struct ForwardedOperationContext *fopc = cls;
1410 struct Peer *remote_peer;
1412 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS ==
1415 remote_peer = fopc->cls;
1416 GNUNET_assert (NULL != remote_peer);
1417 remote_peer->destroy_flag = GNUNET_YES;
1418 if (0 == remote_peer->reference_cnt)
1419 GST_destroy_peer (remote_peer);
1421 GST_forwarded_operation_reply_relay (fopc, msg);
1427 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1430 * @param client identification of the client
1431 * @param message the actual message
1434 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1435 const struct GNUNET_MessageHeader *message)
1437 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1438 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1439 struct GNUNET_CONFIGURATION_Handle *cfg;
1440 struct ForwardedOperationContext *fo_ctxt;
1441 struct Route *route;
1446 uint32_t config_size;
1452 msize = ntohs (message->size);
1453 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1455 GNUNET_break (0); /* We need configuration */
1456 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1459 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1460 host_id = ntohl (msg->host_id);
1461 peer_id = ntohl (msg->peer_id);
1462 if (UINT32_MAX == peer_id)
1464 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1465 "Cannot create peer with given ID");
1466 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1469 if (host_id == GST_context->host_id)
1473 /* We are responsible for this peer */
1474 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1475 config_size = ntohl (msg->config_size);
1476 config = GNUNET_malloc (config_size);
1477 dest_size = config_size;
1480 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1481 (const Bytef *) &msg[1], (uLong) msize)))
1483 GNUNET_break (0); /* uncompression error */
1484 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1487 if (config_size != dest_size)
1489 GNUNET_break (0); /* Uncompressed config size mismatch */
1490 GNUNET_free (config);
1491 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1494 cfg = GNUNET_CONFIGURATION_create ();
1496 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1498 GNUNET_break (0); /* Configuration parsing error */
1499 GNUNET_free (config);
1500 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1503 GNUNET_free (config);
1504 GNUNET_CONFIGURATION_set_value_number (cfg, "TESTBED", "PEERID",
1505 (unsigned long long) peer_id);
1506 peer = GNUNET_malloc (sizeof (struct Peer));
1507 peer->is_remote = GNUNET_NO;
1508 peer->details.local.cfg = cfg;
1510 LOG_DEBUG ("Creating peer with id: %u\n", (unsigned int) peer->id);
1511 peer->details.local.peer =
1512 GNUNET_TESTING_peer_configure (GST_context->system,
1513 peer->details.local.cfg, peer->id,
1514 NULL /* Peer id */ ,
1516 if (NULL == peer->details.local.peer)
1518 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1522 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1525 peer->details.local.is_running = GNUNET_NO;
1526 peer_list_add (peer);
1528 GNUNET_malloc (sizeof
1529 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1530 reply->header.size =
1531 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1532 reply->header.type =
1533 htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS);
1534 reply->peer_id = msg->peer_id;
1535 reply->operation_id = msg->operation_id;
1536 GST_queue_message (client, &reply->header);
1537 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1541 /* Forward peer create request */
1542 route = GST_find_dest_route (host_id);
1546 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1550 peer = GNUNET_malloc (sizeof (struct Peer));
1551 peer->is_remote = GNUNET_YES;
1553 peer->details.remote.slave = GST_slave_list[route->dest];
1554 peer->details.remote.remote_host_id = host_id;
1555 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1556 GNUNET_SERVER_client_keep (client);
1557 fo_ctxt->client = client;
1558 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1559 fo_ctxt->cls = peer; //GST_slave_list[route->dest]->controller;
1560 fo_ctxt->type = OP_PEER_CREATE;
1562 GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list
1563 [route->dest]->controller,
1564 fo_ctxt->operation_id,
1566 peer_create_success_cb, fo_ctxt);
1567 fo_ctxt->timeout_task =
1568 GNUNET_SCHEDULER_add_delayed (GST_timeout, &peer_create_forward_timeout,
1570 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
1571 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1576 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1579 * @param client identification of the client
1580 * @param message the actual message
1583 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
1584 const struct GNUNET_MessageHeader *message)
1586 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1587 struct ForwardedOperationContext *fopc;
1591 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1592 peer_id = ntohl (msg->peer_id);
1593 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1594 peer_id, GNUNET_ntohll (msg->operation_id));
1595 if ((GST_peer_list_size <= peer_id) || (NULL == GST_peer_list[peer_id]))
1597 LOG (GNUNET_ERROR_TYPE_ERROR,
1598 "Asked to destroy a non existent peer with id: %u\n", peer_id);
1599 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1600 "Peer doesn't exist");
1601 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1604 peer = GST_peer_list[peer_id];
1605 if (GNUNET_YES == peer->is_remote)
1607 /* Forward the destory message to sub controller */
1608 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1609 GNUNET_SERVER_client_keep (client);
1610 fopc->client = client;
1612 fopc->type = OP_PEER_DESTROY;
1613 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1615 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1617 fopc->operation_id, &msg->header,
1618 &peer_destroy_success_cb, fopc);
1619 fopc->timeout_task =
1620 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1622 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1623 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1626 peer->destroy_flag = GNUNET_YES;
1627 if (0 == peer->reference_cnt)
1628 GST_destroy_peer (peer);
1630 LOG (GNUNET_ERROR_TYPE_DEBUG,
1631 "Delaying peer destroy as peer is currently in use\n");
1632 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1633 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1638 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1641 * @param client identification of the client
1642 * @param message the actual message
1645 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
1646 const struct GNUNET_MessageHeader *message)
1648 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1649 struct GNUNET_TESTBED_PeerEventMessage *reply;
1650 struct ForwardedOperationContext *fopc;
1654 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
1655 peer_id = ntohl (msg->peer_id);
1656 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1659 LOG (GNUNET_ERROR_TYPE_ERROR,
1660 "Asked to start a non existent peer with id: %u\n", peer_id);
1661 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1664 peer = GST_peer_list[peer_id];
1665 if (GNUNET_YES == peer->is_remote)
1667 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1668 GNUNET_SERVER_client_keep (client);
1669 fopc->client = client;
1670 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1671 fopc->type = OP_PEER_START;
1673 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1675 fopc->operation_id, &msg->header,
1676 &GST_forwarded_operation_reply_relay,
1678 fopc->timeout_task =
1679 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1681 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1682 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1685 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
1687 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1689 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1692 peer->details.local.is_running = GNUNET_YES;
1693 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1694 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
1695 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1696 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
1697 reply->host_id = htonl (GST_context->host_id);
1698 reply->peer_id = msg->peer_id;
1699 reply->operation_id = msg->operation_id;
1700 GST_queue_message (client, &reply->header);
1701 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1706 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1709 * @param client identification of the client
1710 * @param message the actual message
1713 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
1714 const struct GNUNET_MessageHeader *message)
1716 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1717 struct GNUNET_TESTBED_PeerEventMessage *reply;
1718 struct ForwardedOperationContext *fopc;
1722 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
1723 peer_id = ntohl (msg->peer_id);
1724 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PEER_STOP for peer %u\n", peer_id);
1725 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1727 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1729 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1732 peer = GST_peer_list[peer_id];
1733 if (GNUNET_YES == peer->is_remote)
1735 LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarding PEER_STOP for peer %u\n",
1737 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1738 GNUNET_SERVER_client_keep (client);
1739 fopc->client = client;
1740 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1741 fopc->type = OP_PEER_STOP;
1743 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1745 fopc->operation_id, &msg->header,
1746 &GST_forwarded_operation_reply_relay,
1748 fopc->timeout_task =
1749 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1751 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1752 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1755 if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer))
1757 LOG (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %u failed\n", peer_id);
1758 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1759 "Peer not running");
1760 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1763 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %u successfully stopped\n", peer_id);
1764 peer->details.local.is_running = GNUNET_NO;
1765 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1766 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
1767 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1768 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
1769 reply->host_id = htonl (GST_context->host_id);
1770 reply->peer_id = msg->peer_id;
1771 reply->operation_id = msg->operation_id;
1772 GST_queue_message (client, &reply->header);
1773 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1774 GNUNET_TESTING_peer_wait (peer->details.local.peer);
1779 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
1782 * @param client identification of the client
1783 * @param message the actual message
1786 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1787 const struct GNUNET_MessageHeader *message)
1789 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
1790 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
1799 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
1800 peer_id = ntohl (msg->peer_id);
1801 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1803 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1805 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1808 peer = GST_peer_list[peer_id];
1809 if (GNUNET_YES == peer->is_remote)
1811 struct ForwardedOperationContext *fopc;
1813 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", peer_id);
1814 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1815 GNUNET_SERVER_client_keep (client);
1816 fopc->client = client;
1817 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1818 fopc->type = OP_PEER_INFO;
1820 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1822 fopc->operation_id, &msg->header,
1823 &GST_forwarded_operation_reply_relay,
1825 fopc->timeout_task =
1826 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout,
1828 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1829 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1832 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", peer_id);
1834 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg,
1836 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
1837 GNUNET_free (config);
1840 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1841 reply = GNUNET_realloc (xconfig, msize);
1842 (void) memmove (&reply[1], reply, xc_size);
1843 reply->header.size = htons (msize);
1844 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION);
1845 reply->peer_id = msg->peer_id;
1846 reply->operation_id = msg->operation_id;
1847 GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer,
1848 &reply->peer_identity);
1849 reply->config_size = htons ((uint16_t) c_size);
1850 GST_queue_message (client, &reply->header);
1851 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1856 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
1859 * @param client identification of the client
1860 * @param message the actual message
1863 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1864 const struct GNUNET_MessageHeader *message)
1866 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
1867 struct Slave *slave;
1868 struct GNUNET_TESTBED_SlaveConfiguration *reply;
1872 size_t xconfig_size;
1877 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
1878 slave_id = ntohl (msg->slave_id);
1879 op_id = GNUNET_ntohll (msg->operation_id);
1880 if ((GST_slave_list_size <= slave_id) || (NULL == GST_slave_list[slave_id]))
1882 /* FIXME: Add forwardings for this type of message here.. */
1883 GST_send_operation_fail_msg (client, op_id, "Slave not found");
1884 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1887 slave = GST_slave_list[slave_id];
1888 if (NULL == slave->cfg)
1890 GST_send_operation_fail_msg (client, op_id,
1891 "Configuration not found (slave not started by me)");
1892 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1895 config = GNUNET_CONFIGURATION_serialize (slave->cfg, &config_size);
1897 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
1898 GNUNET_free (config);
1899 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
1900 GNUNET_break (reply_size <= UINT16_MAX);
1901 GNUNET_break (config_size <= UINT16_MAX);
1902 reply = GNUNET_realloc (xconfig, reply_size);
1903 (void) memmove (&reply[1], reply, xconfig_size);
1904 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION);
1905 reply->header.size = htons ((uint16_t) reply_size);
1906 reply->slave_id = msg->slave_id;
1907 reply->operation_id = msg->operation_id;
1908 reply->config_size = htons ((uint16_t) config_size);
1909 GST_queue_message (client, &reply->header);
1910 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1915 * Iterator over hash map entries.
1917 * @param cls closure
1918 * @param key current key code
1919 * @param value value in the hash map
1920 * @return GNUNET_YES if we should continue to
1925 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1927 struct SharedService *ss = value;
1929 GNUNET_assert (GNUNET_YES ==
1930 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
1931 GNUNET_free (ss->name);
1938 * Iterator for freeing hash map entries in a slave's reghost_map
1940 * @param cls handle to the slave
1941 * @param key current key code
1942 * @param value value in the hash map
1943 * @return GNUNET_YES if we should continue to
1948 reghost_free_iterator (void *cls, const struct GNUNET_HashCode *key,
1951 struct Slave *slave = cls;
1952 struct RegisteredHostContext *rhc = value;
1953 struct ForwardedOverlayConnectContext *focc;
1955 GNUNET_assert (GNUNET_YES ==
1956 GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key,
1958 while (NULL != (focc = rhc->focc_dll_head))
1960 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc);
1961 GST_cleanup_focc (focc);
1963 if (NULL != rhc->sub_op)
1964 GNUNET_TESTBED_operation_done (rhc->sub_op);
1965 if (NULL != rhc->client)
1966 GNUNET_SERVER_client_drop (rhc->client);
1967 GNUNET_free (value);
1973 * Task to clean up and shutdown nicely
1976 * @param tc the TaskContext from scheduler
1979 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1981 struct LCFContextQueue *lcfq;
1982 struct ForwardedOperationContext *fopc;
1983 struct MessageQueue *mq_entry;
1986 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
1987 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
1988 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
1990 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
1991 /* cleanup any remaining forwarded operations */
1992 while (NULL != (fopc = fopcq_head))
1994 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
1995 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
1996 if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
1997 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
1998 GNUNET_SERVER_client_drop (fopc->client);
2001 case OP_PEER_CREATE:
2002 GNUNET_free (fopc->cls);
2006 case OP_PEER_DESTROY:
2008 case OP_OVERLAY_CONNECT:
2009 case OP_LINK_CONTROLLERS:
2010 case OP_GET_SLAVE_CONFIG:
2017 if (NULL != lcfq_head)
2019 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
2021 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
2022 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
2025 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
2026 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
2028 GNUNET_free (lcfq->lcf->msg);
2029 GNUNET_free (lcfq->lcf);
2030 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
2035 /* Clear peer list */
2036 for (id = 0; id < GST_peer_list_size; id++)
2037 if (NULL != GST_peer_list[id])
2039 /* If destroy flag is set it means that this peer should have been
2040 * destroyed by a context which we destroy before */
2041 GNUNET_break (GNUNET_NO == GST_peer_list[id]->destroy_flag);
2042 /* counter should be zero as we free all contexts before */
2043 GNUNET_break (0 == GST_peer_list[id]->reference_cnt);
2044 if ((GNUNET_NO == GST_peer_list[id]->is_remote) &&
2045 (GNUNET_YES == GST_peer_list[id]->details.local.is_running))
2046 GNUNET_TESTING_peer_kill (GST_peer_list[id]->details.local.peer);
2048 for (id = 0; id < GST_peer_list_size; id++)
2049 if (NULL != GST_peer_list[id])
2051 if (GNUNET_NO == GST_peer_list[id]->is_remote)
2053 if (GNUNET_YES == GST_peer_list[id]->details.local.is_running)
2054 GNUNET_TESTING_peer_wait (GST_peer_list[id]->details.local.peer);
2055 GNUNET_TESTING_peer_destroy (GST_peer_list[id]->details.local.peer);
2056 GNUNET_CONFIGURATION_destroy (GST_peer_list[id]->details.local.cfg);
2058 GNUNET_free (GST_peer_list[id]);
2060 GNUNET_free_non_null (GST_peer_list);
2061 /* Clear host list */
2062 for (id = 0; id < GST_host_list_size; id++)
2063 if (NULL != GST_host_list[id])
2064 GNUNET_TESTBED_host_destroy (GST_host_list[id]);
2065 GNUNET_free_non_null (GST_host_list);
2066 /* Clear route list */
2067 for (id = 0; id < route_list_size; id++)
2068 if (NULL != route_list[id])
2069 GNUNET_free (route_list[id]);
2070 GNUNET_free_non_null (route_list);
2071 /* Clear GST_slave_list */
2072 for (id = 0; id < GST_slave_list_size; id++)
2073 if (NULL != GST_slave_list[id])
2075 struct HostRegistration *hr_entry;
2077 while (NULL != (hr_entry = GST_slave_list[id]->hr_dll_head))
2079 GNUNET_CONTAINER_DLL_remove (GST_slave_list[id]->hr_dll_head,
2080 GST_slave_list[id]->hr_dll_tail, hr_entry);
2081 GNUNET_free (hr_entry);
2083 if (NULL != GST_slave_list[id]->rhandle)
2084 GNUNET_TESTBED_cancel_registration (GST_slave_list[id]->rhandle);
2086 GNUNET_CONTAINER_multihashmap_iterate (GST_slave_list
2088 reghost_free_iterator,
2089 GST_slave_list[id]);
2090 GNUNET_CONTAINER_multihashmap_destroy (GST_slave_list[id]->reghost_map);
2091 if (NULL != GST_slave_list[id]->cfg)
2092 GNUNET_CONFIGURATION_destroy (GST_slave_list[id]->cfg);
2093 if (NULL != GST_slave_list[id]->controller)
2094 GNUNET_TESTBED_controller_disconnect (GST_slave_list[id]->controller);
2095 if (NULL != GST_slave_list[id]->controller_proc)
2096 GNUNET_TESTBED_controller_stop (GST_slave_list[id]->controller_proc);
2097 GNUNET_free (GST_slave_list[id]);
2099 GNUNET_free_non_null (GST_slave_list);
2100 if (NULL != GST_context)
2102 GNUNET_free_non_null (GST_context->master_ip);
2103 if (NULL != GST_context->system)
2104 GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
2105 GNUNET_SERVER_client_drop (GST_context->client);
2106 GNUNET_free (GST_context);
2109 if (NULL != transmit_handle)
2110 GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle);
2111 while (NULL != (mq_entry = mq_head))
2113 GNUNET_free (mq_entry->msg);
2114 GNUNET_SERVER_client_drop (mq_entry->client);
2115 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
2116 GNUNET_free (mq_entry);
2118 GNUNET_free_non_null (hostname);
2119 GNUNET_CONFIGURATION_destroy (our_config);
2120 /* Free hello cache */
2122 GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
2123 GST_opq_openfds = NULL;
2128 * Callback for client disconnect
2131 * @param client the client which has disconnected
2134 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
2136 if (NULL == GST_context)
2138 if (client == GST_context->client)
2140 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
2141 /* should not be needed as we're terminated by failure to read
2142 * from stdin, but if stdin fails for some reason, this shouldn't
2143 * hurt for now --- might need to revise this later if we ever
2144 * decide that master connections might be temporarily down
2145 * for some reason */
2146 //GNUNET_SCHEDULER_shutdown ();
2154 * @param cls closure
2155 * @param server the initialized server
2156 * @param cfg configuration to use
2159 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
2160 const struct GNUNET_CONFIGURATION_Handle *cfg)
2162 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
2163 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
2164 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
2165 {&handle_configure_shared_service, NULL,
2166 GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE, 0},
2167 {&handle_link_controllers, NULL,
2168 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, 0},
2169 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, 0},
2170 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER,
2171 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
2172 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER,
2173 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
2174 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER,
2175 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
2176 {&handle_peer_get_config, NULL,
2177 GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION,
2178 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
2179 {&GST_handle_overlay_connect, NULL,
2180 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT,
2181 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
2182 {&GST_handle_remote_overlay_connect, NULL,
2183 GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, 0},
2184 {handle_slave_get_config, NULL,
2185 GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION,
2186 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
2190 unsigned long long num;
2193 GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
2196 GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile));
2197 GNUNET_free (logfile);
2199 GNUNET_assert (GNUNET_OK ==
2200 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2201 "CACHE_SIZE", &num));
2202 GST_cache_init ((unsigned int) num);
2203 GNUNET_assert (GNUNET_OK ==
2204 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2205 "MAX_OPEN_FDS", &num));
2206 GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ ((unsigned int) num);
2207 GNUNET_assert (GNUNET_OK ==
2208 GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
2209 "OPERATION_TIMEOUT",
2211 GNUNET_TIME_Relative *)
2213 GNUNET_assert (GNUNET_OK ==
2214 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
2215 "HOSTNAME", &hostname));
2216 our_config = GNUNET_CONFIGURATION_dup (cfg);
2217 GNUNET_SERVER_add_handlers (server, message_handlers);
2218 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
2219 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
2221 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
2222 GNUNET_SCHEDULER_PRIORITY_IDLE,
2223 &shutdown_task, NULL);
2224 LOG_DEBUG ("Testbed startup complete\n");
2225 event_mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
2230 * The starting point of execution
2233 main (int argc, char *const *argv)
2235 //sleep (15); /* Debugging */
2236 return (GNUNET_OK ==
2237 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
2238 &testbed_run, NULL)) ? 0 : 1;
2241 /* end of gnunet-service-testbed.c */