2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/gnunet-service-testbed.c
23 * @brief implementation of the TESTBED service
24 * @author Sree Harsha Totakura
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 * The size of the host list
79 unsigned int GST_host_list_size;
82 * The size of directly linked neighbours list
84 unsigned int GST_slave_list_size;
87 * The size of the peer list
89 unsigned int GST_peer_list_size;
92 /***********************************/
93 /* Local definitions and variables */
94 /***********************************/
97 * The message queue for sending messages to clients
102 * The message to be sent
104 struct GNUNET_MessageHeader *msg;
107 * The client to send the message to
109 struct GNUNET_SERVER_Client *client;
112 * next pointer for DLL
114 struct MessageQueue *next;
117 * prev pointer for DLL
119 struct MessageQueue *prev;
123 * Our hostname; we give this to all the peers we start
125 static char *hostname;
128 * Current Transmit Handle; NULL if no notify transmit exists currently
130 static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
133 * The head for the LCF queue
135 static struct LCFContextQueue *lcfq_head;
138 * The tail for the LCF queue
140 static struct LCFContextQueue *lcfq_tail;
143 * The message queue head
145 static struct MessageQueue *mq_head;
148 * The message queue tail
150 static struct MessageQueue *mq_tail;
153 * The hashmap of shared services
155 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
160 static struct Route **route_list;
163 * The event mask for the events we listen from sub-controllers
165 static uint64_t event_mask;
168 * The size of the route list
170 static unsigned int route_list_size;
173 * The lcf_task handle
175 static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
178 * The shutdown task handle
180 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
184 * Function called to notify a client about the connection begin ready to queue
185 * more data. "buf" will be NULL and "size" zero if the connection was closed
186 * for writing in the meantime.
189 * @param size number of bytes available in buf
190 * @param buf where the callee should write the message
191 * @return number of bytes written to buf
194 transmit_ready_notify (void *cls, size_t size, void *buf)
196 struct MessageQueue *mq_entry;
198 transmit_handle = NULL;
200 GNUNET_assert (NULL != mq_entry);
203 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
204 size = ntohs (mq_entry->msg->size);
205 memcpy (buf, mq_entry->msg, size);
206 GNUNET_free (mq_entry->msg);
207 GNUNET_SERVER_client_drop (mq_entry->client);
208 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
209 GNUNET_free (mq_entry);
211 if (NULL != mq_entry)
213 GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
214 ntohs (mq_entry->msg->size),
215 GNUNET_TIME_UNIT_FOREVER_REL,
216 &transmit_ready_notify, NULL);
222 * Queues a message in send queue for sending to the service
224 * @param client the client to whom the queued message has to be sent
225 * @param msg the message to queue
228 GST_queue_message (struct GNUNET_SERVER_Client *client,
229 struct GNUNET_MessageHeader *msg)
231 struct MessageQueue *mq_entry;
235 type = ntohs (msg->type);
236 size = ntohs (msg->size);
237 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
238 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
239 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
241 mq_entry->client = client;
242 GNUNET_SERVER_client_keep (client);
243 LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type,
245 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
246 if (NULL == transmit_handle)
248 GNUNET_SERVER_notify_transmit_ready (client, size,
249 GNUNET_TIME_UNIT_FOREVER_REL,
250 &transmit_ready_notify, NULL);
255 * Similar to GNUNET_array_grow(); however instead of calling GNUNET_array_grow()
256 * several times we call it only once. The array is also made to grow in steps
259 * @param ptr the array pointer to grow
260 * @param size the size of array
261 * @param accommodate_size the size which the array has to accommdate; after
262 * this call the array will be big enough to accommdate sizes upto
265 #define array_grow_large_enough(ptr, size, accommodate_size) \
268 unsigned int growth_size; \
269 GNUNET_assert (size <= accommodate_size); \
270 growth_size = size; \
271 while (growth_size <= accommodate_size) \
272 growth_size += LIST_GROW_STEP; \
273 GNUNET_array_grow (ptr, size, growth_size); \
274 GNUNET_assert (size > accommodate_size); \
279 * Function to add a host to the current list of known hosts
281 * @param host the host to add
282 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
286 host_list_add (struct GNUNET_TESTBED_Host *host)
290 host_id = GNUNET_TESTBED_host_get_id_ (host);
291 if (GST_host_list_size <= host_id)
292 array_grow_large_enough (GST_host_list, GST_host_list_size, host_id);
293 if (NULL != GST_host_list[host_id])
295 LOG_DEBUG ("A host with id: %u already exists\n", host_id);
296 return GNUNET_SYSERR;
298 GST_host_list[host_id] = host;
304 * Adds a route to the route list
306 * @param route the route to add
309 route_list_add (struct Route *route)
311 if (route->dest >= route_list_size)
312 array_grow_large_enough (route_list, route_list_size, route->dest);
313 GNUNET_assert (NULL == route_list[route->dest]);
314 route_list[route->dest] = route;
319 * Adds a slave to the slave array
321 * @param slave the slave controller to add
324 slave_list_add (struct Slave *slave)
326 if (slave->host_id >= GST_slave_list_size)
327 array_grow_large_enough (GST_slave_list, GST_slave_list_size, slave->host_id);
328 GNUNET_assert (NULL == GST_slave_list[slave->host_id]);
329 GST_slave_list[slave->host_id] = slave;
334 * Adds a peer to the peer array
336 * @param peer the peer to add
339 peer_list_add (struct Peer *peer)
341 if (peer->id >= GST_peer_list_size)
342 array_grow_large_enough (GST_peer_list, GST_peer_list_size, peer->id);
343 GNUNET_assert (NULL == GST_peer_list[peer->id]);
344 GST_peer_list[peer->id] = peer;
349 * Removes a the give peer from the peer array
351 * @param peer the peer to be removed
354 peer_list_remove (struct Peer *peer)
356 unsigned int orig_size;
359 GST_peer_list[peer->id] = NULL;
360 orig_size = GST_peer_list_size;
361 while (GST_peer_list_size >= LIST_GROW_STEP)
363 for (id = GST_peer_list_size - 1;
364 (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); id--)
365 if (NULL != GST_peer_list[id])
367 if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1))
369 GST_peer_list_size -= LIST_GROW_STEP;
371 if (orig_size == GST_peer_list_size)
374 GNUNET_realloc (GST_peer_list, sizeof (struct Peer *) * GST_peer_list_size);
379 * Finds the route with directly connected host as destination through which
380 * the destination host can be reached
382 * @param host_id the id of the destination host
383 * @return the route with directly connected destination host; NULL if no route
387 GST_find_dest_route (uint32_t host_id)
391 if (route_list_size <= host_id)
393 while (NULL != (route = route_list[host_id]))
395 if (route->thru == GST_context->host_id)
397 host_id = route->thru;
404 * Routes message to a host given its host_id
406 * @param host_id the id of the destination host
407 * @param msg the message to be routed
410 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
417 * Send operation failure message to client
419 * @param client the client to which the failure message has to be sent to
420 * @param operation_id the id of the failed operation
421 * @param emsg the error message; can be NULL
424 GST_send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
425 uint64_t operation_id, const char *emsg)
427 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
431 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
432 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
434 msg = GNUNET_malloc (msize);
435 msg->header.size = htons (msize);
436 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONFAILEVENT);
437 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
438 msg->operation_id = GNUNET_htonll (operation_id);
440 memcpy (&msg[1], emsg, emsg_len);
441 GST_queue_message (client, &msg->header);
446 * Function to send generic operation success message to given client
448 * @param client the client to send the message to
449 * @param operation_id the id of the operation which was successful
452 send_operation_success_msg (struct GNUNET_SERVER_Client *client,
453 uint64_t operation_id)
455 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
458 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
459 msg = GNUNET_malloc (msize);
460 msg->header.size = htons (msize);
461 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
462 msg->operation_id = GNUNET_htonll (operation_id);
463 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
464 GST_queue_message (client, &msg->header);
469 * Callback which will be called to after a host registration succeeded or failed
471 * @param cls the handle to the slave at which the registration is completed
472 * @param emsg the error message; NULL if host registration is successful
475 hr_completion (void *cls, const char *emsg);
479 * Attempts to register the next host in the host registration queue
481 * @param slave the slave controller whose host registration queue is checked
482 * for host registrations
485 register_next_host (struct Slave *slave)
487 struct HostRegistration *hr;
489 hr = slave->hr_dll_head;
490 GNUNET_assert (NULL != hr);
491 GNUNET_assert (NULL == slave->rhandle);
492 LOG (GNUNET_ERROR_TYPE_DEBUG,
493 "Registering host %u at %u\n",
494 GNUNET_TESTBED_host_get_id_ (hr->host),
495 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
496 slave->rhandle = GNUNET_TESTBED_register_host (slave->controller,
504 * Callback which will be called to after a host registration succeeded or failed
506 * @param cls the handle to the slave at which the registration is completed
507 * @param emsg the error message; NULL if host registration is successful
510 hr_completion (void *cls, const char *emsg)
512 struct Slave *slave = cls;
513 struct HostRegistration *hr;
515 slave->rhandle = NULL;
516 hr = slave->hr_dll_head;
517 GNUNET_assert (NULL != hr);
518 LOG (GNUNET_ERROR_TYPE_DEBUG,
519 "Registering host %u at %u successful\n",
520 GNUNET_TESTBED_host_get_id_ (hr->host),
521 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
522 GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head,
526 hr->cb (hr->cb_cls, emsg);
528 if (NULL != slave->hr_dll_head)
529 register_next_host (slave);
534 * Adds a host registration's request to a slave's registration queue
536 * @param slave the slave controller at which the given host has to be
538 * @param cb the host registration completion callback
539 * @param cb_cls the closure for the host registration completion callback
540 * @param host the host which has to be registered
543 GST_queue_host_registration (struct Slave *slave,
544 GNUNET_TESTBED_HostRegistrationCompletion cb,
546 struct GNUNET_TESTBED_Host *host)
548 struct HostRegistration *hr;
551 LOG (GNUNET_ERROR_TYPE_DEBUG,
552 "Queueing host registration for host %u at %u\n",
553 GNUNET_TESTBED_host_get_id_ (host),
554 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
555 hr = GNUNET_malloc (sizeof (struct HostRegistration));
559 call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO;
560 GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head,
563 if (GNUNET_YES == call_register)
564 register_next_host (slave);
569 * The Link Controller forwarding task
571 * @param cls the LCFContext
572 * @param tc the Task context from scheduler
575 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
579 * Completion callback for host registrations while forwarding Link Controller messages
581 * @param cls the LCFContext
582 * @param emsg the error message; NULL if host registration is successful
585 lcf_proc_cc (void *cls, const char *emsg)
587 struct LCFContext *lcf = cls;
589 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
594 goto registration_error;
595 lcf->state = DELEGATED_HOST_REGISTERED;
596 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
598 case DELEGATED_HOST_REGISTERED:
600 goto registration_error;
601 lcf->state = SLAVE_HOST_REGISTERED;
602 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
605 GNUNET_assert (0); /* Shouldn't reach here */
610 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
612 lcf->state = FINISHED;
613 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
618 * Callback to relay the reply msg of a forwarded operation back to the client
620 * @param cls ForwardedOperationContext
621 * @param msg the message to relay
624 GST_forwarded_operation_reply_relay (void *cls,
625 const struct GNUNET_MessageHeader *msg)
627 struct ForwardedOperationContext *fopc = cls;
628 struct GNUNET_MessageHeader *dup_msg;
631 msize = ntohs (msg->size);
632 LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type),
634 dup_msg = GNUNET_copy_message (msg);
635 GST_queue_message (fopc->client, dup_msg);
636 GNUNET_SERVER_client_drop (fopc->client);
637 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
638 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
644 * Task to free resources when forwarded operation has been timedout
646 * @param cls the ForwardedOperationContext
647 * @param tc the task context from scheduler
650 GST_forwarded_operation_timeout (void *cls,
651 const struct GNUNET_SCHEDULER_TaskContext *tc)
653 struct ForwardedOperationContext *fopc = cls;
655 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
656 LOG (GNUNET_ERROR_TYPE_WARNING, "A forwarded operation has timed out\n");
657 GST_send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
658 GNUNET_SERVER_client_drop (fopc->client);
659 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
665 * The Link Controller forwarding task
667 * @param cls the LCFContext
668 * @param tc the Task context from scheduler
671 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
675 * Callback to be called when forwarded link controllers operation is
676 * successfull. We have to relay the reply msg back to the client
678 * @param cls the LCFContext
679 * @param msg the message to relay
682 lcf_forwarded_operation_reply_relay (void *cls,
683 const struct GNUNET_MessageHeader *msg)
685 struct LCFContext *lcf = cls;
687 GNUNET_assert (NULL != lcf->fopc);
688 GST_forwarded_operation_reply_relay (lcf->fopc, msg);
690 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
691 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
696 * Task to free resources when forwarded link controllers has been timedout
698 * @param cls the LCFContext
699 * @param tc the task context from scheduler
702 lcf_forwarded_operation_timeout (void *cls,
703 const struct GNUNET_SCHEDULER_TaskContext *tc)
705 struct LCFContext *lcf = cls;
707 GNUNET_assert (NULL != lcf->fopc);
708 lcf->fopc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
709 GST_forwarded_operation_timeout (lcf->fopc, tc);
711 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
712 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
717 * The Link Controller forwarding task
719 * @param cls the LCFContext
720 * @param tc the Task context from scheduler
723 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
725 struct LCFContext *lcf = cls;
726 struct LCFContextQueue *lcfq;
728 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
733 GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->delegated_host_id],
734 lcf->gateway->controller))
736 GST_queue_host_registration (lcf->gateway,
738 GST_host_list[lcf->delegated_host_id]);
742 lcf->state = DELEGATED_HOST_REGISTERED;
743 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
746 case DELEGATED_HOST_REGISTERED:
748 GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id],
749 lcf->gateway->controller))
751 GST_queue_host_registration (lcf->gateway,
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 (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,
818 rhc->gateway->controller,
823 GNUNET_TESTBED_operation_done (old_op);
826 LOG_DEBUG ("OL: Linking controllers successfull\n");
827 GNUNET_TESTBED_operation_done (rhc->sub_op);
829 rhc->state = RHC_OL_CONNECT;
830 GST_process_next_focc (rhc);
839 * Callback to signal successfull startup of the controller process
841 * @param cls the handle to the slave whose status is to be found here
842 * @param cfg the configuration with which the controller has been started;
843 * NULL if status is not GNUNET_OK
844 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
845 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
848 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
851 struct Slave *slave = cls;
852 struct LinkControllersContext *lcc;
855 if (GNUNET_SYSERR == status)
857 slave->controller_proc = NULL;
858 GST_slave_list[slave->host_id] = NULL;
859 if (NULL != slave->cfg)
860 GNUNET_CONFIGURATION_destroy (slave->cfg);
863 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
864 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
868 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
870 &slave_event_callback, slave);
871 if (NULL != slave->controller)
873 send_operation_success_msg (lcc->client, lcc->operation_id);
874 slave->cfg = GNUNET_CONFIGURATION_dup (cfg);
878 GST_send_operation_fail_msg (lcc->client, lcc->operation_id,
879 "Could not connect to delegated controller");
880 GNUNET_TESTBED_controller_stop (slave->controller_proc);
881 GST_slave_list[slave->host_id] = NULL;
889 if (NULL != lcc->client)
891 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
892 GNUNET_SERVER_client_drop (lcc->client);
903 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
906 * @param client identification of the client
907 * @param message the actual message
910 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
911 const struct GNUNET_MessageHeader *message)
913 const struct GNUNET_TESTBED_InitMessage *msg;
914 struct GNUNET_TESTBED_Host *host;
915 const char *controller_hostname;
918 if (NULL != GST_context)
920 LOG_DEBUG ("We are being connected to laterally\n");
921 GNUNET_SERVER_receive_done (client, GNUNET_OK);
924 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
925 msize = ntohs (message->size);
926 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
929 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
932 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
933 controller_hostname = (const char *) &msg[1];
934 if ('\0' != controller_hostname[msize - 1])
937 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
940 GST_context = GNUNET_malloc (sizeof (struct Context));
941 GNUNET_SERVER_client_keep (client);
942 GST_context->client = client;
943 GST_context->host_id = ntohl (msg->host_id);
944 GST_context->master_ip = GNUNET_strdup (controller_hostname);
945 LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
946 GST_context->system =
947 GNUNET_TESTING_system_create ("testbed", GST_context->master_ip, hostname);
949 GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
950 GST_context->master_ip,
953 host_list_add (host);
954 LOG_DEBUG ("Created master context with host ID: %u\n",
955 GST_context->host_id);
956 GNUNET_SERVER_receive_done (client, GNUNET_OK);
961 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
964 * @param client identification of the client
965 * @param message the actual message
968 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
969 const struct GNUNET_MessageHeader *message)
971 struct GNUNET_TESTBED_Host *host;
972 const struct GNUNET_TESTBED_AddHostMessage *msg;
973 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
978 uint16_t username_length;
979 uint16_t hostname_length;
983 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
984 msize = ntohs (msg->header.size);
985 username = (char *) &msg[1];
986 username_length = ntohs (msg->user_name_length);
987 if (0 != username_length)
989 /* msg must contain hostname */
990 GNUNET_assert (msize > (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
991 username_length + 1));
992 if (0 != username_length)
993 GNUNET_assert ('\0' == username[username_length - 1]);
994 hostname = username + username_length;
996 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
997 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
998 GNUNET_assert (strlen (hostname) == hostname_length - 1);
999 host_id = ntohl (msg->host_id);
1000 LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
1001 LOG_DEBUG ("-------host id: %u\n", host_id);
1002 LOG_DEBUG ("-------hostname: %s\n", hostname);
1003 if (0 != username_length)
1004 LOG_DEBUG ("-------username: %s\n", username);
1007 LOG_DEBUG ("-------username: NULL\n");
1010 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1012 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1013 ntohs (msg->ssh_port));
1014 GNUNET_assert (NULL != host);
1015 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1016 if (GNUNET_OK != host_list_add (host))
1018 /* We are unable to add a host */
1019 emsg = "A host exists with given host-id";
1020 LOG_DEBUG ("%s: %u", emsg, host_id);
1021 GNUNET_TESTBED_host_destroy (host);
1022 reply_size += strlen (emsg) + 1;
1023 reply = GNUNET_malloc (reply_size);
1024 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1028 LOG_DEBUG ("Added host %u at %u\n",
1029 host_id, GST_context->host_id);
1030 reply = GNUNET_malloc (reply_size);
1032 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
1033 reply->header.size = htons (reply_size);
1034 reply->host_id = htonl (host_id);
1035 GST_queue_message (client, &reply->header);
1036 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1041 * Iterator over hash map entries.
1043 * @param cls closure
1044 * @param key current key code
1045 * @param value value in the hash map
1046 * @return GNUNET_YES if we should continue to
1051 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1053 struct SharedService *queried_ss = cls;
1054 struct SharedService *ss = value;
1056 if (0 == strcmp (ss->name, queried_ss->name))
1064 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1067 * @param client identification of the client
1068 * @param message the actual message
1071 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1072 const struct GNUNET_MessageHeader *message)
1074 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1075 struct SharedService *ss;
1077 struct GNUNET_HashCode hash;
1079 uint16_t service_name_size;
1081 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1082 msg_size = ntohs (message->size);
1083 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1086 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1090 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1091 service_name = (char *) &msg[1];
1092 if ('\0' != service_name[service_name_size - 1])
1095 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1098 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1099 service_name, ntohl (msg->num_peers));
1100 if (ntohl (msg->host_id) != GST_context->host_id)
1102 route_message (ntohl (msg->host_id), message);
1103 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1106 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1107 ss = GNUNET_malloc (sizeof (struct SharedService));
1108 ss->name = strdup (service_name);
1109 ss->num_shared = ntohl (msg->num_peers);
1110 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1111 if (GNUNET_SYSERR ==
1112 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1113 &ss_exists_iterator, ss))
1115 LOG (GNUNET_ERROR_TYPE_WARNING,
1116 "Service %s already configured as a shared service. "
1117 "Ignoring service sharing request \n", ss->name);
1118 GNUNET_free (ss->name);
1122 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1123 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1128 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1131 * @param client identification of the client
1132 * @param message the actual message
1135 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1136 const struct GNUNET_MessageHeader *message)
1138 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1139 struct GNUNET_CONFIGURATION_Handle *cfg;
1140 struct LCFContextQueue *lcfq;
1141 struct Route *route;
1142 struct Route *new_route;
1146 uint32_t delegated_host_id;
1147 uint32_t slave_host_id;
1150 if (NULL == GST_context)
1153 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1156 msize = ntohs (message->size);
1157 if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
1160 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1163 msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
1164 delegated_host_id = ntohl (msg->delegated_host_id);
1165 if (delegated_host_id == GST_context->host_id)
1168 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1169 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1172 if ((delegated_host_id >= GST_host_list_size) ||
1173 (NULL == GST_host_list[delegated_host_id]))
1175 LOG (GNUNET_ERROR_TYPE_WARNING,
1176 "Delegated host %u not registered with us\n", delegated_host_id);
1177 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1180 slave_host_id = ntohl (msg->slave_host_id);
1181 if ((slave_host_id >= GST_host_list_size) || (NULL == GST_host_list[slave_host_id]))
1183 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n",
1185 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1188 if (slave_host_id == delegated_host_id)
1190 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1191 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1195 if (slave_host_id == GST_context->host_id) /* Link from us */
1197 struct Slave *slave;
1198 struct LinkControllersContext *lcc;
1200 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1201 config_size = ntohs (msg->config_size);
1202 if ((delegated_host_id < GST_slave_list_size) && (NULL != GST_slave_list[delegated_host_id])) /* We have already added */
1204 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1206 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1209 config = GNUNET_malloc (config_size);
1210 dest_size = (uLongf) config_size;
1212 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1215 GNUNET_break (0); /* Compression error */
1216 GNUNET_free (config);
1217 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1220 if (config_size != dest_size)
1222 LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1223 GNUNET_free (config);
1224 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1227 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1229 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1231 GNUNET_break (0); /* Configuration parsing error */
1232 GNUNET_free (config);
1233 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1236 GNUNET_free (config);
1237 if ((delegated_host_id < GST_slave_list_size) &&
1238 (NULL != GST_slave_list[delegated_host_id]))
1240 GNUNET_break (0); /* Configuration parsing error */
1241 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1244 slave = GNUNET_malloc (sizeof (struct Slave));
1245 slave->host_id = delegated_host_id;
1246 slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
1247 slave_list_add (slave);
1248 if (1 != msg->is_subordinate)
1251 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
1253 &slave_event_callback, slave);
1255 if (NULL != slave->controller)
1256 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1258 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1259 "Could not connect to delegated controller");
1260 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1263 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1264 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1265 GNUNET_SERVER_client_keep (client);
1266 lcc->client = client;
1268 slave->controller_proc =
1269 GNUNET_TESTBED_controller_start (GST_context->master_ip,
1270 GST_host_list[slave->host_id], cfg,
1271 &slave_status_callback, slave);
1272 GNUNET_CONFIGURATION_destroy (cfg);
1273 new_route = GNUNET_malloc (sizeof (struct Route));
1274 new_route->dest = delegated_host_id;
1275 new_route->thru = GST_context->host_id;
1276 route_list_add (new_route);
1280 /* Route the request */
1281 if (slave_host_id >= route_list_size)
1283 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1284 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1287 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1288 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1289 lcfq->lcf->delegated_host_id = delegated_host_id;
1290 lcfq->lcf->slave_host_id = slave_host_id;
1291 route = GST_find_dest_route (slave_host_id);
1292 GNUNET_assert (NULL != route); /* because we add routes carefully */
1293 GNUNET_assert (route->dest < GST_slave_list_size);
1294 GNUNET_assert (NULL != GST_slave_list[route->dest]);
1295 lcfq->lcf->state = INIT;
1296 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1297 lcfq->lcf->gateway = GST_slave_list[route->dest];
1298 lcfq->lcf->msg = GNUNET_malloc (msize);
1299 (void) memcpy (lcfq->lcf->msg, msg, msize);
1300 GNUNET_SERVER_client_keep (client);
1301 lcfq->lcf->client = client;
1302 if (NULL == lcfq_head)
1304 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1305 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1306 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1309 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1310 /* FIXME: Adding a new route should happen after the controllers are linked
1312 if (1 != msg->is_subordinate)
1314 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1317 if ((delegated_host_id < route_list_size)
1318 && (NULL != route_list[delegated_host_id]))
1320 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1321 with is subordinate flag set to GNUNET_YES? */
1322 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1325 new_route = GNUNET_malloc (sizeof (struct Route));
1326 new_route->dest = delegated_host_id;
1327 new_route->thru = route->dest;
1328 route_list_add (new_route);
1329 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1334 * The task to be executed if the forwarded peer create operation has been
1337 * @param cls the FowardedOperationContext
1338 * @param tc the TaskContext from the scheduler
1341 peer_create_forward_timeout (void *cls,
1342 const struct GNUNET_SCHEDULER_TaskContext *tc)
1344 struct ForwardedOperationContext *fopc = cls;
1346 GNUNET_free (fopc->cls);
1347 GST_forwarded_operation_timeout (fopc, tc);
1352 * Callback to be called when forwarded peer create operation is successfull. We
1353 * have to relay the reply msg back to the client
1355 * @param cls ForwardedOperationContext
1356 * @param msg the peer create success message
1359 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1361 struct ForwardedOperationContext *fopc = cls;
1362 struct Peer *remote_peer;
1364 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
1366 GNUNET_assert (NULL != fopc->cls);
1367 remote_peer = fopc->cls;
1368 peer_list_add (remote_peer);
1370 GST_forwarded_operation_reply_relay (fopc, msg);
1375 * Function to destroy a peer
1377 * @param peer the peer structure to destroy
1380 GST_destroy_peer (struct Peer *peer)
1382 GNUNET_break (0 == peer->reference_cnt);
1383 if (GNUNET_YES == peer->is_remote)
1385 peer_list_remove (peer);
1389 if (GNUNET_YES == peer->details.local.is_running)
1391 GNUNET_TESTING_peer_stop (peer->details.local.peer);
1392 peer->details.local.is_running = GNUNET_NO;
1394 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1395 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
1396 peer_list_remove (peer);
1402 * Callback to be called when forwarded peer destroy operation is successfull. We
1403 * have to relay the reply msg back to the client
1405 * @param cls ForwardedOperationContext
1406 * @param msg the peer create success message
1409 peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1411 struct ForwardedOperationContext *fopc = cls;
1412 struct Peer *remote_peer;
1414 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS == ntohs (msg->type))
1416 remote_peer = fopc->cls;
1417 GNUNET_assert (NULL != remote_peer);
1418 remote_peer->destroy_flag = GNUNET_YES;
1419 if (0 == remote_peer->reference_cnt)
1420 GST_destroy_peer (remote_peer);
1422 GST_forwarded_operation_reply_relay (fopc, msg);
1428 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1431 * @param client identification of the client
1432 * @param message the actual message
1435 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1436 const struct GNUNET_MessageHeader *message)
1438 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1439 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1440 struct GNUNET_CONFIGURATION_Handle *cfg;
1441 struct ForwardedOperationContext *fo_ctxt;
1442 struct Route *route;
1447 uint32_t config_size;
1453 msize = ntohs (message->size);
1454 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1456 GNUNET_break (0); /* We need configuration */
1457 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1460 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1461 host_id = ntohl (msg->host_id);
1462 peer_id = ntohl (msg->peer_id);
1463 if (UINT32_MAX == peer_id)
1465 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1466 "Cannot create peer with given ID");
1467 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1470 if (host_id == GST_context->host_id)
1474 /* We are responsible for this peer */
1475 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1476 config_size = ntohl (msg->config_size);
1477 config = GNUNET_malloc (config_size);
1478 dest_size = config_size;
1481 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1482 (const Bytef *) &msg[1], (uLong) msize)))
1484 GNUNET_break (0); /* uncompression error */
1485 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1488 if (config_size != dest_size)
1490 GNUNET_break (0); /* Uncompressed config size mismatch */
1491 GNUNET_free (config);
1492 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1495 cfg = GNUNET_CONFIGURATION_create ();
1497 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1499 GNUNET_break (0); /* Configuration parsing error */
1500 GNUNET_free (config);
1501 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1504 GNUNET_free (config);
1505 GNUNET_CONFIGURATION_set_value_number (cfg,
1508 (unsigned long long) peer_id);
1509 peer = GNUNET_malloc (sizeof (struct Peer));
1510 peer->is_remote = GNUNET_NO;
1511 peer->details.local.cfg = cfg;
1513 LOG_DEBUG ("Creating peer with id: %u\n",
1514 (unsigned int) peer->id);
1515 peer->details.local.peer =
1516 GNUNET_TESTING_peer_configure (GST_context->system,
1517 peer->details.local.cfg, peer->id,
1518 NULL /* Peer id */ ,
1520 if (NULL == peer->details.local.peer)
1522 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1526 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1529 peer->details.local.is_running = GNUNET_NO;
1530 peer_list_add (peer);
1532 GNUNET_malloc (sizeof
1533 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1534 reply->header.size =
1535 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1536 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
1537 reply->peer_id = msg->peer_id;
1538 reply->operation_id = msg->operation_id;
1539 GST_queue_message (client, &reply->header);
1540 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1544 /* Forward peer create request */
1545 route = GST_find_dest_route (host_id);
1549 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1553 peer = GNUNET_malloc (sizeof (struct Peer));
1554 peer->is_remote = GNUNET_YES;
1556 peer->details.remote.slave = GST_slave_list[route->dest];
1557 peer->details.remote.remote_host_id = host_id;
1558 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1559 GNUNET_SERVER_client_keep (client);
1560 fo_ctxt->client = client;
1561 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1562 fo_ctxt->cls = peer; //GST_slave_list[route->dest]->controller;
1563 fo_ctxt->type = OP_PEER_CREATE;
1565 GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list [route->dest]->controller,
1566 fo_ctxt->operation_id,
1568 peer_create_success_cb, fo_ctxt);
1569 fo_ctxt->timeout_task =
1570 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
1572 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
1573 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1578 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1581 * @param client identification of the client
1582 * @param message the actual message
1585 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
1586 const struct GNUNET_MessageHeader *message)
1588 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1589 struct ForwardedOperationContext *fopc;
1593 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1594 peer_id = ntohl (msg->peer_id);
1595 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1596 peer_id, GNUNET_ntohll (msg->operation_id));
1597 if ((GST_peer_list_size <= peer_id) || (NULL == GST_peer_list[peer_id]))
1599 LOG (GNUNET_ERROR_TYPE_ERROR,
1600 "Asked to destroy a non existent peer with id: %u\n", peer_id);
1601 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1602 "Peer doesn't exist");
1603 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1606 peer = GST_peer_list[peer_id];
1607 if (GNUNET_YES == peer->is_remote)
1609 /* Forward the destory message to sub controller */
1610 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1611 GNUNET_SERVER_client_keep (client);
1612 fopc->client = client;
1614 fopc->type = OP_PEER_DESTROY;
1615 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1617 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
1618 fopc->operation_id, &msg->header,
1619 &peer_destroy_success_cb,
1621 fopc->timeout_task =
1622 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &GST_forwarded_operation_timeout,
1624 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1625 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1628 peer->destroy_flag = GNUNET_YES;
1629 if (0 == peer->reference_cnt)
1630 GST_destroy_peer (peer);
1632 LOG (GNUNET_ERROR_TYPE_DEBUG,
1633 "Delaying peer destroy as peer is currently in use\n");
1634 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1635 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1640 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1643 * @param client identification of the client
1644 * @param message the actual message
1647 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
1648 const struct GNUNET_MessageHeader *message)
1650 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1651 struct GNUNET_TESTBED_PeerEventMessage *reply;
1652 struct ForwardedOperationContext *fopc;
1656 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
1657 peer_id = ntohl (msg->peer_id);
1658 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1661 LOG (GNUNET_ERROR_TYPE_ERROR,
1662 "Asked to start a non existent peer with id: %u\n", peer_id);
1663 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1666 peer = GST_peer_list[peer_id];
1667 if (GNUNET_YES == peer->is_remote)
1669 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1670 GNUNET_SERVER_client_keep (client);
1671 fopc->client = client;
1672 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1673 fopc->type = OP_PEER_START;
1675 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
1676 fopc->operation_id, &msg->header,
1677 &GST_forwarded_operation_reply_relay,
1679 fopc->timeout_task =
1680 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &GST_forwarded_operation_timeout,
1682 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1683 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1686 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
1688 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1690 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1693 peer->details.local.is_running = GNUNET_YES;
1694 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1695 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
1696 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1697 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
1698 reply->host_id = htonl (GST_context->host_id);
1699 reply->peer_id = msg->peer_id;
1700 reply->operation_id = msg->operation_id;
1701 GST_queue_message (client, &reply->header);
1702 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1707 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1710 * @param client identification of the client
1711 * @param message the actual message
1714 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
1715 const struct GNUNET_MessageHeader *message)
1717 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1718 struct GNUNET_TESTBED_PeerEventMessage *reply;
1719 struct ForwardedOperationContext *fopc;
1723 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
1724 peer_id = ntohl (msg->peer_id);
1725 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PEER_STOP for peer %u\n", peer_id);
1726 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1728 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1730 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1733 peer = GST_peer_list[peer_id];
1734 if (GNUNET_YES == peer->is_remote)
1736 LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarding PEER_STOP for peer %u\n", peer_id);
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.slave->controller,
1744 fopc->operation_id, &msg->header,
1745 &GST_forwarded_operation_reply_relay,
1747 fopc->timeout_task =
1748 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &GST_forwarded_operation_timeout,
1750 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1751 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1754 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer->details.local.peer))
1756 LOG (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %u failed\n", peer_id);
1757 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1758 "Peer not running");
1759 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1762 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %u successfully stopped\n", peer_id);
1763 peer->details.local.is_running = GNUNET_NO;
1764 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1765 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
1766 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1767 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
1768 reply->host_id = htonl (GST_context->host_id);
1769 reply->peer_id = msg->peer_id;
1770 reply->operation_id = msg->operation_id;
1771 GST_queue_message (client, &reply->header);
1772 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1777 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
1780 * @param client identification of the client
1781 * @param message the actual message
1784 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1785 const struct GNUNET_MessageHeader *message)
1787 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
1788 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
1797 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
1798 peer_id = ntohl (msg->peer_id);
1799 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1801 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1803 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1806 peer = GST_peer_list[peer_id];
1807 if (GNUNET_YES == peer->is_remote)
1809 struct ForwardedOperationContext *fopc;
1811 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", peer_id);
1812 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1813 GNUNET_SERVER_client_keep (client);
1814 fopc->client = client;
1815 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1816 fopc->type = OP_PEER_INFO;
1818 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
1819 fopc->operation_id, &msg->header,
1820 &GST_forwarded_operation_reply_relay,
1822 fopc->timeout_task =
1823 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &GST_forwarded_operation_timeout,
1825 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1826 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1829 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", peer_id);
1831 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg,
1833 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
1834 GNUNET_free (config);
1837 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1838 reply = GNUNET_realloc (xconfig, msize);
1839 (void) memmove (&reply[1], reply, xc_size);
1840 reply->header.size = htons (msize);
1841 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG);
1842 reply->peer_id = msg->peer_id;
1843 reply->operation_id = msg->operation_id;
1844 GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer,
1845 &reply->peer_identity);
1846 reply->config_size = htons ((uint16_t) c_size);
1847 GST_queue_message (client, &reply->header);
1848 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1853 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
1856 * @param client identification of the client
1857 * @param message the actual message
1860 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1861 const struct GNUNET_MessageHeader *message)
1863 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
1864 struct Slave *slave;
1865 struct GNUNET_TESTBED_SlaveConfiguration *reply;
1869 size_t xconfig_size;
1874 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
1875 slave_id = ntohl (msg->slave_id);
1876 op_id = GNUNET_ntohll (msg->operation_id);
1877 if ((GST_slave_list_size <= slave_id) || (NULL == GST_slave_list[slave_id]))
1879 /* FIXME: Add forwardings for this type of message here.. */
1880 GST_send_operation_fail_msg (client, op_id, "Slave not found");
1881 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1884 slave = GST_slave_list[slave_id];
1885 if (NULL == slave->cfg)
1887 GST_send_operation_fail_msg (client, op_id,
1888 "Configuration not found (slave not started by me)");
1889 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1892 config = GNUNET_CONFIGURATION_serialize (slave->cfg, &config_size);
1893 xconfig_size = GNUNET_TESTBED_compress_config_ (config, config_size,
1895 GNUNET_free (config);
1896 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
1897 GNUNET_break (reply_size <= UINT16_MAX);
1898 GNUNET_break (config_size <= UINT16_MAX);
1899 reply = GNUNET_realloc (xconfig, reply_size);
1900 (void) memmove (&reply[1], reply, xconfig_size);
1901 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG);
1902 reply->header.size = htons ((uint16_t) reply_size);
1903 reply->slave_id = msg->slave_id;
1904 reply->operation_id = msg->operation_id;
1905 reply->config_size = htons ((uint16_t) config_size);
1906 GST_queue_message (client, &reply->header);
1907 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1912 * Iterator over hash map entries.
1914 * @param cls closure
1915 * @param key current key code
1916 * @param value value in the hash map
1917 * @return GNUNET_YES if we should continue to
1922 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1924 struct SharedService *ss = value;
1926 GNUNET_assert (GNUNET_YES ==
1927 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
1928 GNUNET_free (ss->name);
1935 * Iterator for freeing hash map entries in a slave's reghost_map
1937 * @param cls handle to the slave
1938 * @param key current key code
1939 * @param value value in the hash map
1940 * @return GNUNET_YES if we should continue to
1945 reghost_free_iterator (void *cls,
1946 const struct GNUNET_HashCode * key,
1949 struct Slave *slave = cls;
1950 struct RegisteredHostContext *rhc = value;
1951 struct ForwardedOverlayConnectContext *focc;
1953 GNUNET_assert (GNUNET_YES ==
1954 GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map,
1956 while (NULL != (focc = rhc->focc_dll_head))
1958 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head,
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,
2082 GNUNET_free (hr_entry);
2084 if (NULL != GST_slave_list[id]->rhandle)
2085 GNUNET_TESTBED_cancel_registration (GST_slave_list[id]->rhandle);
2086 (void) GNUNET_CONTAINER_multihashmap_iterate (GST_slave_list[id]->reghost_map,
2087 reghost_free_iterator,
2088 GST_slave_list[id]);
2089 GNUNET_CONTAINER_multihashmap_destroy (GST_slave_list[id]->reghost_map);
2090 if (NULL != GST_slave_list[id]->cfg)
2091 GNUNET_CONFIGURATION_destroy (GST_slave_list[id]->cfg);
2092 if (NULL != GST_slave_list[id]->controller)
2093 GNUNET_TESTBED_controller_disconnect (GST_slave_list[id]->controller);
2094 if (NULL != GST_slave_list[id]->controller_proc)
2095 GNUNET_TESTBED_controller_stop (GST_slave_list[id]->controller_proc);
2096 GNUNET_free (GST_slave_list[id]);
2098 GNUNET_free_non_null (GST_slave_list);
2099 if (NULL != GST_context)
2101 GNUNET_free_non_null (GST_context->master_ip);
2102 if (NULL != GST_context->system)
2103 GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
2104 GNUNET_SERVER_client_drop (GST_context->client);
2105 GNUNET_free (GST_context);
2108 if (NULL != transmit_handle)
2109 GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle);
2110 while (NULL != (mq_entry = mq_head))
2112 GNUNET_free (mq_entry->msg);
2113 GNUNET_SERVER_client_drop (mq_entry->client);
2114 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
2115 GNUNET_free (mq_entry);
2117 GNUNET_free_non_null (hostname);
2118 GNUNET_CONFIGURATION_destroy (our_config);
2119 /* Free hello cache */
2121 GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
2122 GST_opq_openfds = NULL;
2127 * Callback for client disconnect
2130 * @param client the client which has disconnected
2133 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
2135 if (NULL == GST_context)
2137 if (client == GST_context->client)
2139 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
2140 /* should not be needed as we're terminated by failure to read
2141 * from stdin, but if stdin fails for some reason, this shouldn't
2142 * hurt for now --- might need to revise this later if we ever
2143 * decide that master connections might be temporarily down
2144 * for some reason */
2145 //GNUNET_SCHEDULER_shutdown ();
2153 * @param cls closure
2154 * @param server the initialized server
2155 * @param cfg configuration to use
2158 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
2159 const struct GNUNET_CONFIGURATION_Handle *cfg)
2161 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
2162 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
2163 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
2164 {&handle_configure_shared_service, NULL,
2165 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
2166 {&handle_link_controllers, NULL,
2167 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
2168 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
2169 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER,
2170 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
2171 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER,
2172 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
2173 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER,
2174 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
2175 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG,
2176 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
2177 {&GST_handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT,
2178 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
2179 {&GST_handle_overlay_request_connect, NULL,
2180 GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT, 0},
2181 {handle_slave_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG,
2182 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
2186 unsigned long long num;
2188 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
2193 GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile));
2194 GNUNET_free (logfile);
2196 GNUNET_assert (GNUNET_OK ==
2197 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2200 GST_cache_init ((unsigned int) num);
2201 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
2202 (cfg, "testbed", "HOSTNAME", &hostname));
2203 our_config = GNUNET_CONFIGURATION_dup (cfg);
2204 GNUNET_SERVER_add_handlers (server, message_handlers);
2205 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
2206 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
2207 GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ (GST_QLEN_OPENFDS);
2209 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
2210 GNUNET_SCHEDULER_PRIORITY_IDLE,
2211 &shutdown_task, NULL);
2212 LOG_DEBUG ("Testbed startup complete\n");
2213 event_mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
2218 * The starting point of execution
2221 main (int argc, char *const *argv)
2223 //sleep (15); /* Debugging */
2224 return (GNUNET_OK ==
2225 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
2226 &testbed_run, NULL)) ? 0 : 1;
2229 /* end of gnunet-service-testbed.c */