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,
329 GNUNET_assert (NULL == GST_slave_list[slave->host_id]);
330 GST_slave_list[slave->host_id] = slave;
335 * Adds a peer to the peer array
337 * @param peer the peer to add
340 peer_list_add (struct Peer *peer)
342 if (peer->id >= GST_peer_list_size)
343 array_grow_large_enough (GST_peer_list, GST_peer_list_size, peer->id);
344 GNUNET_assert (NULL == GST_peer_list[peer->id]);
345 GST_peer_list[peer->id] = peer;
350 * Removes a the give peer from the peer array
352 * @param peer the peer to be removed
355 peer_list_remove (struct Peer *peer)
357 unsigned int orig_size;
360 GST_peer_list[peer->id] = NULL;
361 orig_size = GST_peer_list_size;
362 while (GST_peer_list_size >= LIST_GROW_STEP)
364 for (id = GST_peer_list_size - 1;
365 (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX);
367 if (NULL != GST_peer_list[id])
369 if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1))
371 GST_peer_list_size -= LIST_GROW_STEP;
373 if (orig_size == GST_peer_list_size)
376 GNUNET_realloc (GST_peer_list,
377 sizeof (struct Peer *) * GST_peer_list_size);
382 * Finds the route with directly connected host as destination through which
383 * the destination host can be reached
385 * @param host_id the id of the destination host
386 * @return the route with directly connected destination host; NULL if no route
390 GST_find_dest_route (uint32_t host_id)
394 if (route_list_size <= host_id)
396 while (NULL != (route = route_list[host_id]))
398 if (route->thru == GST_context->host_id)
400 host_id = route->thru;
407 * Routes message to a host given its host_id
409 * @param host_id the id of the destination host
410 * @param msg the message to be routed
413 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
420 * Send operation failure message to client
422 * @param client the client to which the failure message has to be sent to
423 * @param operation_id the id of the failed operation
424 * @param emsg the error message; can be NULL
427 GST_send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
428 uint64_t operation_id, const char *emsg)
430 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
434 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
435 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
437 msg = GNUNET_malloc (msize);
438 msg->header.size = htons (msize);
439 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT);
440 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
441 msg->operation_id = GNUNET_htonll (operation_id);
443 memcpy (&msg[1], emsg, emsg_len);
444 GST_queue_message (client, &msg->header);
449 * Function to send generic operation success message to given client
451 * @param client the client to send the message to
452 * @param operation_id the id of the operation which was successful
455 send_operation_success_msg (struct GNUNET_SERVER_Client *client,
456 uint64_t operation_id)
458 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
461 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
462 msg = GNUNET_malloc (msize);
463 msg->header.size = htons (msize);
465 htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS);
466 msg->operation_id = GNUNET_htonll (operation_id);
467 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
468 GST_queue_message (client, &msg->header);
473 * Callback which will be called to after a host registration succeeded or failed
475 * @param cls the handle to the slave at which the registration is completed
476 * @param emsg the error message; NULL if host registration is successful
479 hr_completion (void *cls, const char *emsg);
483 * Attempts to register the next host in the host registration queue
485 * @param slave the slave controller whose host registration queue is checked
486 * for host registrations
489 register_next_host (struct Slave *slave)
491 struct HostRegistration *hr;
493 hr = slave->hr_dll_head;
494 GNUNET_assert (NULL != hr);
495 GNUNET_assert (NULL == slave->rhandle);
496 LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n",
497 GNUNET_TESTBED_host_get_id_ (hr->host),
498 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
500 GNUNET_TESTBED_register_host (slave->controller, hr->host, hr_completion,
506 * Callback which will be called to after a host registration succeeded or failed
508 * @param cls the handle to the slave at which the registration is completed
509 * @param emsg the error message; NULL if host registration is successful
512 hr_completion (void *cls, const char *emsg)
514 struct Slave *slave = cls;
515 struct HostRegistration *hr;
517 slave->rhandle = NULL;
518 hr = slave->hr_dll_head;
519 GNUNET_assert (NULL != hr);
520 LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u successful\n",
521 GNUNET_TESTBED_host_get_id_ (hr->host),
522 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
523 GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail, hr);
525 hr->cb (hr->cb_cls, emsg);
527 if (NULL != slave->hr_dll_head)
528 register_next_host (slave);
533 * Adds a host registration's request to a slave's registration queue
535 * @param slave the slave controller at which the given host has to be
537 * @param cb the host registration completion callback
538 * @param cb_cls the closure for the host registration completion callback
539 * @param host the host which has to be registered
542 GST_queue_host_registration (struct Slave *slave,
543 GNUNET_TESTBED_HostRegistrationCompletion cb,
544 void *cb_cls, struct GNUNET_TESTBED_Host *host)
546 struct HostRegistration *hr;
549 LOG (GNUNET_ERROR_TYPE_DEBUG,
550 "Queueing host registration for host %u at %u\n",
551 GNUNET_TESTBED_host_get_id_ (host),
552 GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
553 hr = GNUNET_malloc (sizeof (struct HostRegistration));
557 call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO;
558 GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head, slave->hr_dll_tail, hr);
559 if (GNUNET_YES == call_register)
560 register_next_host (slave);
565 * The Link Controller forwarding task
567 * @param cls the LCFContext
568 * @param tc the Task context from scheduler
571 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
575 * Completion callback for host registrations while forwarding Link Controller messages
577 * @param cls the LCFContext
578 * @param emsg the error message; NULL if host registration is successful
581 lcf_proc_cc (void *cls, const char *emsg)
583 struct LCFContext *lcf = cls;
585 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
590 goto registration_error;
591 lcf->state = DELEGATED_HOST_REGISTERED;
592 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
594 case DELEGATED_HOST_REGISTERED:
596 goto registration_error;
597 lcf->state = SLAVE_HOST_REGISTERED;
598 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
601 GNUNET_assert (0); /* Shouldn't reach here */
606 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
608 lcf->state = FINISHED;
609 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
614 * Callback to relay the reply msg of a forwarded operation back to the client
616 * @param cls ForwardedOperationContext
617 * @param msg the message to relay
620 GST_forwarded_operation_reply_relay (void *cls,
621 const struct GNUNET_MessageHeader *msg)
623 struct ForwardedOperationContext *fopc = cls;
624 struct GNUNET_MessageHeader *dup_msg;
627 msize = ntohs (msg->size);
628 LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type),
630 dup_msg = GNUNET_copy_message (msg);
631 GST_queue_message (fopc->client, dup_msg);
632 GNUNET_SERVER_client_drop (fopc->client);
633 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
634 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
640 * Task to free resources when forwarded operation has been timedout
642 * @param cls the ForwardedOperationContext
643 * @param tc the task context from scheduler
646 GST_forwarded_operation_timeout (void *cls,
647 const struct GNUNET_SCHEDULER_TaskContext *tc)
649 struct ForwardedOperationContext *fopc = cls;
651 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
652 LOG (GNUNET_ERROR_TYPE_WARNING, "A forwarded operation has timed out\n");
653 GST_send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
654 GNUNET_SERVER_client_drop (fopc->client);
655 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
661 * The Link Controller forwarding task
663 * @param cls the LCFContext
664 * @param tc the Task context from scheduler
667 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
671 * Callback to be called when forwarded link controllers operation is
672 * successfull. We have to relay the reply msg back to the client
674 * @param cls the LCFContext
675 * @param msg the message to relay
678 lcf_forwarded_operation_reply_relay (void *cls,
679 const struct GNUNET_MessageHeader *msg)
681 struct LCFContext *lcf = cls;
683 GNUNET_assert (NULL != lcf->fopc);
684 GST_forwarded_operation_reply_relay (lcf->fopc, msg);
686 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
687 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
692 * Task to free resources when forwarded link controllers has been timedout
694 * @param cls the LCFContext
695 * @param tc the task context from scheduler
698 lcf_forwarded_operation_timeout (void *cls,
699 const struct GNUNET_SCHEDULER_TaskContext *tc)
701 struct LCFContext *lcf = cls;
703 GNUNET_assert (NULL != lcf->fopc);
704 lcf->fopc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
705 GST_forwarded_operation_timeout (lcf->fopc, tc);
707 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
708 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
713 * The Link Controller forwarding task
715 * @param cls the LCFContext
716 * @param tc the Task context from scheduler
719 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
721 struct LCFContext *lcf = cls;
722 struct LCFContextQueue *lcfq;
724 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
729 GNUNET_TESTBED_is_host_registered_ (GST_host_list
730 [lcf->delegated_host_id],
731 lcf->gateway->controller))
733 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
734 GST_host_list[lcf->delegated_host_id]);
738 lcf->state = DELEGATED_HOST_REGISTERED;
739 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
742 case DELEGATED_HOST_REGISTERED:
744 GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id],
745 lcf->gateway->controller))
747 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
748 GST_host_list[lcf->slave_host_id]);
752 lcf->state = SLAVE_HOST_REGISTERED;
753 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
756 case SLAVE_HOST_REGISTERED:
757 lcf->fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
758 lcf->fopc->client = lcf->client;
759 lcf->fopc->operation_id = lcf->operation_id;
760 lcf->fopc->type = OP_LINK_CONTROLLERS;
762 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
765 &lcf_forwarded_operation_reply_relay,
767 lcf->fopc->timeout_task =
768 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &lcf_forwarded_operation_timeout,
770 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, lcf->fopc);
771 lcf->state = FINISHED;
775 GNUNET_assert (lcfq->lcf == lcf);
776 GNUNET_free (lcf->msg);
778 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
780 if (NULL != lcfq_head)
782 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
788 * Callback for event from slave controllers
790 * @param cls struct Slave *
791 * @param event information about the event
794 slave_event_callback (void *cls,
795 const struct GNUNET_TESTBED_EventInformation *event)
797 struct RegisteredHostContext *rhc;
798 struct GNUNET_CONFIGURATION_Handle *cfg;
799 struct GNUNET_TESTBED_Operation *old_op;
801 /* We currently only get here when working on RegisteredHostContexts */
802 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
803 rhc = event->details.operation_finished.op_cls;
804 GNUNET_assert (rhc->sub_op == event->details.operation_finished.operation);
808 cfg = event->details.operation_finished.generic;
809 old_op = rhc->sub_op;
810 rhc->state = RHC_LINK;
812 GNUNET_TESTBED_controller_link (rhc, rhc->gateway->controller,
813 rhc->reg_host, rhc->host, cfg,
815 GNUNET_TESTBED_operation_done (old_op);
818 LOG_DEBUG ("OL: Linking controllers successfull\n");
819 GNUNET_TESTBED_operation_done (rhc->sub_op);
821 rhc->state = RHC_OL_CONNECT;
822 GST_process_next_focc (rhc);
831 * Callback to signal successfull startup of the controller process
833 * @param cls the handle to the slave whose status is to be found here
834 * @param cfg the configuration with which the controller has been started;
835 * NULL if status is not GNUNET_OK
836 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
837 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
840 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
843 struct Slave *slave = cls;
844 struct LinkControllersContext *lcc;
847 if (GNUNET_SYSERR == status)
849 slave->controller_proc = NULL;
850 GST_slave_list[slave->host_id] = NULL;
851 if (NULL != slave->cfg)
852 GNUNET_CONFIGURATION_destroy (slave->cfg);
855 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
856 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
860 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
861 event_mask, &slave_event_callback,
863 if (NULL != slave->controller)
865 send_operation_success_msg (lcc->client, lcc->operation_id);
866 slave->cfg = GNUNET_CONFIGURATION_dup (cfg);
870 GST_send_operation_fail_msg (lcc->client, lcc->operation_id,
871 "Could not connect to delegated controller");
872 GNUNET_TESTBED_controller_stop (slave->controller_proc);
873 GST_slave_list[slave->host_id] = NULL;
881 if (NULL != lcc->client)
883 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
884 GNUNET_SERVER_client_drop (lcc->client);
895 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
898 * @param client identification of the client
899 * @param message the actual message
902 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
903 const struct GNUNET_MessageHeader *message)
905 const struct GNUNET_TESTBED_InitMessage *msg;
906 struct GNUNET_TESTBED_Host *host;
907 const char *controller_hostname;
910 if (NULL != GST_context)
912 LOG_DEBUG ("We are being connected to laterally\n");
913 GNUNET_SERVER_receive_done (client, GNUNET_OK);
916 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
917 msize = ntohs (message->size);
918 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
921 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
924 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
925 controller_hostname = (const char *) &msg[1];
926 if ('\0' != controller_hostname[msize - 1])
929 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
932 GST_context = GNUNET_malloc (sizeof (struct Context));
933 GNUNET_SERVER_client_keep (client);
934 GST_context->client = client;
935 GST_context->host_id = ntohl (msg->host_id);
936 GST_context->master_ip = GNUNET_strdup (controller_hostname);
937 LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
938 GST_context->system =
939 GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
942 GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
943 GST_context->master_ip, NULL, 0);
944 host_list_add (host);
945 LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id);
946 GNUNET_SERVER_receive_done (client, GNUNET_OK);
951 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
954 * @param client identification of the client
955 * @param message the actual message
958 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
959 const struct GNUNET_MessageHeader *message)
961 struct GNUNET_TESTBED_Host *host;
962 const struct GNUNET_TESTBED_AddHostMessage *msg;
963 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
968 uint16_t username_length;
969 uint16_t hostname_length;
973 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
974 msize = ntohs (msg->header.size);
975 username = (char *) &msg[1];
976 username_length = ntohs (msg->user_name_length);
977 if (0 != username_length)
979 /* msg must contain hostname */
980 GNUNET_assert (msize >
981 (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
982 username_length + 1));
983 if (0 != username_length)
984 GNUNET_assert ('\0' == username[username_length - 1]);
985 hostname = username + username_length;
987 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
988 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
989 GNUNET_assert (strlen (hostname) == hostname_length - 1);
990 host_id = ntohl (msg->host_id);
991 LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
992 LOG_DEBUG ("-------host id: %u\n", host_id);
993 LOG_DEBUG ("-------hostname: %s\n", hostname);
994 if (0 != username_length)
995 LOG_DEBUG ("-------username: %s\n", username);
998 LOG_DEBUG ("-------username: NULL\n");
1001 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1003 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1004 ntohs (msg->ssh_port));
1005 GNUNET_assert (NULL != host);
1006 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1007 if (GNUNET_OK != host_list_add (host))
1009 /* We are unable to add a host */
1010 emsg = "A host exists with given host-id";
1011 LOG_DEBUG ("%s: %u", emsg, host_id);
1012 GNUNET_TESTBED_host_destroy (host);
1013 reply_size += strlen (emsg) + 1;
1014 reply = GNUNET_malloc (reply_size);
1015 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1019 LOG_DEBUG ("Added host %u at %u\n", host_id, GST_context->host_id);
1020 reply = GNUNET_malloc (reply_size);
1022 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS);
1023 reply->header.size = htons (reply_size);
1024 reply->host_id = htonl (host_id);
1025 GST_queue_message (client, &reply->header);
1026 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1031 * Iterator over hash map entries.
1033 * @param cls closure
1034 * @param key current key code
1035 * @param value value in the hash map
1036 * @return GNUNET_YES if we should continue to
1041 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1043 struct SharedService *queried_ss = cls;
1044 struct SharedService *ss = value;
1046 if (0 == strcmp (ss->name, queried_ss->name))
1054 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1057 * @param client identification of the client
1058 * @param message the actual message
1061 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1062 const struct GNUNET_MessageHeader *message)
1064 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1065 struct SharedService *ss;
1067 struct GNUNET_HashCode hash;
1069 uint16_t service_name_size;
1071 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1072 msg_size = ntohs (message->size);
1073 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1076 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1080 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1081 service_name = (char *) &msg[1];
1082 if ('\0' != service_name[service_name_size - 1])
1085 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1088 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1089 service_name, ntohl (msg->num_peers));
1090 if (ntohl (msg->host_id) != GST_context->host_id)
1092 route_message (ntohl (msg->host_id), message);
1093 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1096 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1097 ss = GNUNET_malloc (sizeof (struct SharedService));
1098 ss->name = strdup (service_name);
1099 ss->num_shared = ntohl (msg->num_peers);
1100 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1101 if (GNUNET_SYSERR ==
1102 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1103 &ss_exists_iterator, ss))
1105 LOG (GNUNET_ERROR_TYPE_WARNING,
1106 "Service %s already configured as a shared service. "
1107 "Ignoring service sharing request \n", ss->name);
1108 GNUNET_free (ss->name);
1112 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1113 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1118 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1121 * @param client identification of the client
1122 * @param message the actual message
1125 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1126 const struct GNUNET_MessageHeader *message)
1128 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1129 struct GNUNET_CONFIGURATION_Handle *cfg;
1130 struct LCFContextQueue *lcfq;
1131 struct Route *route;
1132 struct Route *new_route;
1136 uint32_t delegated_host_id;
1137 uint32_t slave_host_id;
1140 if (NULL == GST_context)
1143 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1146 msize = ntohs (message->size);
1147 if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
1150 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1153 msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
1154 delegated_host_id = ntohl (msg->delegated_host_id);
1155 if (delegated_host_id == GST_context->host_id)
1158 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1159 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1162 if ((delegated_host_id >= GST_host_list_size) ||
1163 (NULL == GST_host_list[delegated_host_id]))
1165 LOG (GNUNET_ERROR_TYPE_WARNING,
1166 "Delegated host %u not registered with us\n", delegated_host_id);
1167 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1170 slave_host_id = ntohl (msg->slave_host_id);
1171 if ((slave_host_id >= GST_host_list_size) ||
1172 (NULL == GST_host_list[slave_host_id]))
1174 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n",
1176 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1179 if (slave_host_id == delegated_host_id)
1181 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1182 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1186 if (slave_host_id == GST_context->host_id) /* Link from us */
1188 struct Slave *slave;
1189 struct LinkControllersContext *lcc;
1191 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1192 config_size = ntohs (msg->config_size);
1193 if ((delegated_host_id < GST_slave_list_size) && (NULL != GST_slave_list[delegated_host_id])) /* We have already added */
1195 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1197 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1200 config = GNUNET_malloc (config_size);
1201 dest_size = (uLongf) config_size;
1203 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1206 GNUNET_break (0); /* Compression error */
1207 GNUNET_free (config);
1208 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1211 if (config_size != dest_size)
1213 LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1214 GNUNET_free (config);
1215 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1218 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1220 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1222 GNUNET_break (0); /* Configuration parsing error */
1223 GNUNET_free (config);
1224 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1227 GNUNET_free (config);
1228 if ((delegated_host_id < GST_slave_list_size) &&
1229 (NULL != GST_slave_list[delegated_host_id]))
1231 GNUNET_break (0); /* Configuration parsing error */
1232 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1235 slave = GNUNET_malloc (sizeof (struct Slave));
1236 slave->host_id = delegated_host_id;
1237 slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
1238 slave_list_add (slave);
1239 if (1 != msg->is_subordinate)
1242 GNUNET_TESTBED_controller_connect (cfg, GST_host_list[slave->host_id],
1243 event_mask, &slave_event_callback,
1246 if (NULL != slave->controller)
1247 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1249 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1250 "Could not connect to delegated controller");
1251 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1254 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1255 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1256 GNUNET_SERVER_client_keep (client);
1257 lcc->client = client;
1259 slave->controller_proc =
1260 GNUNET_TESTBED_controller_start (GST_context->master_ip,
1261 GST_host_list[slave->host_id], cfg,
1262 &slave_status_callback, slave);
1263 GNUNET_CONFIGURATION_destroy (cfg);
1264 new_route = GNUNET_malloc (sizeof (struct Route));
1265 new_route->dest = delegated_host_id;
1266 new_route->thru = GST_context->host_id;
1267 route_list_add (new_route);
1271 /* Route the request */
1272 if (slave_host_id >= route_list_size)
1274 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1275 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1278 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1279 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1280 lcfq->lcf->delegated_host_id = delegated_host_id;
1281 lcfq->lcf->slave_host_id = slave_host_id;
1282 route = GST_find_dest_route (slave_host_id);
1283 GNUNET_assert (NULL != route); /* because we add routes carefully */
1284 GNUNET_assert (route->dest < GST_slave_list_size);
1285 GNUNET_assert (NULL != GST_slave_list[route->dest]);
1286 lcfq->lcf->state = INIT;
1287 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1288 lcfq->lcf->gateway = GST_slave_list[route->dest];
1289 lcfq->lcf->msg = GNUNET_malloc (msize);
1290 (void) memcpy (lcfq->lcf->msg, msg, msize);
1291 GNUNET_SERVER_client_keep (client);
1292 lcfq->lcf->client = client;
1293 if (NULL == lcfq_head)
1295 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1296 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1297 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1300 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1301 /* FIXME: Adding a new route should happen after the controllers are linked
1303 if (1 != msg->is_subordinate)
1305 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1308 if ((delegated_host_id < route_list_size) &&
1309 (NULL != route_list[delegated_host_id]))
1311 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1312 * with is subordinate flag set to GNUNET_YES? */
1313 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1316 new_route = GNUNET_malloc (sizeof (struct Route));
1317 new_route->dest = delegated_host_id;
1318 new_route->thru = route->dest;
1319 route_list_add (new_route);
1320 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1325 * The task to be executed if the forwarded peer create operation has been
1328 * @param cls the FowardedOperationContext
1329 * @param tc the TaskContext from the scheduler
1332 peer_create_forward_timeout (void *cls,
1333 const struct GNUNET_SCHEDULER_TaskContext *tc)
1335 struct ForwardedOperationContext *fopc = cls;
1337 GNUNET_free (fopc->cls);
1338 GST_forwarded_operation_timeout (fopc, tc);
1343 * Callback to be called when forwarded peer create operation is successfull. We
1344 * have to relay the reply msg back to the client
1346 * @param cls ForwardedOperationContext
1347 * @param msg the peer create success message
1350 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1352 struct ForwardedOperationContext *fopc = cls;
1353 struct Peer *remote_peer;
1355 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS)
1357 GNUNET_assert (NULL != fopc->cls);
1358 remote_peer = fopc->cls;
1359 peer_list_add (remote_peer);
1361 GST_forwarded_operation_reply_relay (fopc, msg);
1366 * Function to destroy a peer
1368 * @param peer the peer structure to destroy
1371 GST_destroy_peer (struct Peer *peer)
1373 GNUNET_break (0 == peer->reference_cnt);
1374 if (GNUNET_YES == peer->is_remote)
1376 peer_list_remove (peer);
1380 if (GNUNET_YES == peer->details.local.is_running)
1382 GNUNET_TESTING_peer_stop (peer->details.local.peer);
1383 peer->details.local.is_running = GNUNET_NO;
1385 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1386 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
1387 peer_list_remove (peer);
1393 * Callback to be called when forwarded peer destroy operation is successfull. We
1394 * have to relay the reply msg back to the client
1396 * @param cls ForwardedOperationContext
1397 * @param msg the peer create success message
1400 peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1402 struct ForwardedOperationContext *fopc = cls;
1403 struct Peer *remote_peer;
1405 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS ==
1408 remote_peer = fopc->cls;
1409 GNUNET_assert (NULL != remote_peer);
1410 remote_peer->destroy_flag = GNUNET_YES;
1411 if (0 == remote_peer->reference_cnt)
1412 GST_destroy_peer (remote_peer);
1414 GST_forwarded_operation_reply_relay (fopc, msg);
1420 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1423 * @param client identification of the client
1424 * @param message the actual message
1427 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1428 const struct GNUNET_MessageHeader *message)
1430 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1431 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1432 struct GNUNET_CONFIGURATION_Handle *cfg;
1433 struct ForwardedOperationContext *fo_ctxt;
1434 struct Route *route;
1439 uint32_t config_size;
1445 msize = ntohs (message->size);
1446 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1448 GNUNET_break (0); /* We need configuration */
1449 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1452 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1453 host_id = ntohl (msg->host_id);
1454 peer_id = ntohl (msg->peer_id);
1455 if (UINT32_MAX == peer_id)
1457 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1458 "Cannot create peer with given ID");
1459 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1462 if (host_id == GST_context->host_id)
1466 /* We are responsible for this peer */
1467 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1468 config_size = ntohl (msg->config_size);
1469 config = GNUNET_malloc (config_size);
1470 dest_size = config_size;
1473 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1474 (const Bytef *) &msg[1], (uLong) msize)))
1476 GNUNET_break (0); /* uncompression error */
1477 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1480 if (config_size != dest_size)
1482 GNUNET_break (0); /* Uncompressed config size mismatch */
1483 GNUNET_free (config);
1484 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1487 cfg = GNUNET_CONFIGURATION_create ();
1489 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1491 GNUNET_break (0); /* Configuration parsing error */
1492 GNUNET_free (config);
1493 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1496 GNUNET_free (config);
1497 GNUNET_CONFIGURATION_set_value_number (cfg, "TESTBED", "PEERID",
1498 (unsigned long long) peer_id);
1499 peer = GNUNET_malloc (sizeof (struct Peer));
1500 peer->is_remote = GNUNET_NO;
1501 peer->details.local.cfg = cfg;
1503 LOG_DEBUG ("Creating peer with id: %u\n", (unsigned int) peer->id);
1504 peer->details.local.peer =
1505 GNUNET_TESTING_peer_configure (GST_context->system,
1506 peer->details.local.cfg, peer->id,
1507 NULL /* Peer id */ ,
1509 if (NULL == peer->details.local.peer)
1511 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1515 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1518 peer->details.local.is_running = GNUNET_NO;
1519 peer_list_add (peer);
1521 GNUNET_malloc (sizeof
1522 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1523 reply->header.size =
1524 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1525 reply->header.type =
1526 htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS);
1527 reply->peer_id = msg->peer_id;
1528 reply->operation_id = msg->operation_id;
1529 GST_queue_message (client, &reply->header);
1530 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1534 /* Forward peer create request */
1535 route = GST_find_dest_route (host_id);
1539 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1543 peer = GNUNET_malloc (sizeof (struct Peer));
1544 peer->is_remote = GNUNET_YES;
1546 peer->details.remote.slave = GST_slave_list[route->dest];
1547 peer->details.remote.remote_host_id = host_id;
1548 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1549 GNUNET_SERVER_client_keep (client);
1550 fo_ctxt->client = client;
1551 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1552 fo_ctxt->cls = peer; //GST_slave_list[route->dest]->controller;
1553 fo_ctxt->type = OP_PEER_CREATE;
1555 GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list
1556 [route->dest]->controller,
1557 fo_ctxt->operation_id,
1559 peer_create_success_cb, fo_ctxt);
1560 fo_ctxt->timeout_task =
1561 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
1563 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
1564 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1569 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1572 * @param client identification of the client
1573 * @param message the actual message
1576 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
1577 const struct GNUNET_MessageHeader *message)
1579 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1580 struct ForwardedOperationContext *fopc;
1584 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1585 peer_id = ntohl (msg->peer_id);
1586 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1587 peer_id, GNUNET_ntohll (msg->operation_id));
1588 if ((GST_peer_list_size <= peer_id) || (NULL == GST_peer_list[peer_id]))
1590 LOG (GNUNET_ERROR_TYPE_ERROR,
1591 "Asked to destroy a non existent peer with id: %u\n", peer_id);
1592 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1593 "Peer doesn't exist");
1594 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1597 peer = GST_peer_list[peer_id];
1598 if (GNUNET_YES == peer->is_remote)
1600 /* Forward the destory message to sub controller */
1601 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1602 GNUNET_SERVER_client_keep (client);
1603 fopc->client = client;
1605 fopc->type = OP_PEER_DESTROY;
1606 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1608 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1610 fopc->operation_id, &msg->header,
1611 &peer_destroy_success_cb, fopc);
1612 fopc->timeout_task =
1613 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &GST_forwarded_operation_timeout,
1615 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1616 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1619 peer->destroy_flag = GNUNET_YES;
1620 if (0 == peer->reference_cnt)
1621 GST_destroy_peer (peer);
1623 LOG (GNUNET_ERROR_TYPE_DEBUG,
1624 "Delaying peer destroy as peer is currently in use\n");
1625 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1626 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1631 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1634 * @param client identification of the client
1635 * @param message the actual message
1638 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
1639 const struct GNUNET_MessageHeader *message)
1641 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1642 struct GNUNET_TESTBED_PeerEventMessage *reply;
1643 struct ForwardedOperationContext *fopc;
1647 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
1648 peer_id = ntohl (msg->peer_id);
1649 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1652 LOG (GNUNET_ERROR_TYPE_ERROR,
1653 "Asked to start a non existent peer with id: %u\n", peer_id);
1654 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1657 peer = GST_peer_list[peer_id];
1658 if (GNUNET_YES == peer->is_remote)
1660 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1661 GNUNET_SERVER_client_keep (client);
1662 fopc->client = client;
1663 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1664 fopc->type = OP_PEER_START;
1666 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1668 fopc->operation_id, &msg->header,
1669 &GST_forwarded_operation_reply_relay,
1671 fopc->timeout_task =
1672 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &GST_forwarded_operation_timeout,
1674 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1675 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1678 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
1680 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1682 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1685 peer->details.local.is_running = GNUNET_YES;
1686 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1687 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
1688 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1689 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
1690 reply->host_id = htonl (GST_context->host_id);
1691 reply->peer_id = msg->peer_id;
1692 reply->operation_id = msg->operation_id;
1693 GST_queue_message (client, &reply->header);
1694 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1699 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1702 * @param client identification of the client
1703 * @param message the actual message
1706 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
1707 const struct GNUNET_MessageHeader *message)
1709 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1710 struct GNUNET_TESTBED_PeerEventMessage *reply;
1711 struct ForwardedOperationContext *fopc;
1715 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
1716 peer_id = ntohl (msg->peer_id);
1717 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PEER_STOP for peer %u\n", peer_id);
1718 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1720 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1722 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1725 peer = GST_peer_list[peer_id];
1726 if (GNUNET_YES == peer->is_remote)
1728 LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarding PEER_STOP for peer %u\n",
1730 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1731 GNUNET_SERVER_client_keep (client);
1732 fopc->client = client;
1733 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1734 fopc->type = OP_PEER_STOP;
1736 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1738 fopc->operation_id, &msg->header,
1739 &GST_forwarded_operation_reply_relay,
1741 fopc->timeout_task =
1742 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &GST_forwarded_operation_timeout,
1744 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1745 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1748 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer->details.local.peer))
1750 LOG (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %u failed\n", peer_id);
1751 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1752 "Peer not running");
1753 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1756 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %u successfully stopped\n", peer_id);
1757 peer->details.local.is_running = GNUNET_NO;
1758 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1759 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
1760 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1761 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
1762 reply->host_id = htonl (GST_context->host_id);
1763 reply->peer_id = msg->peer_id;
1764 reply->operation_id = msg->operation_id;
1765 GST_queue_message (client, &reply->header);
1766 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1771 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
1774 * @param client identification of the client
1775 * @param message the actual message
1778 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1779 const struct GNUNET_MessageHeader *message)
1781 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
1782 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
1791 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
1792 peer_id = ntohl (msg->peer_id);
1793 if ((peer_id >= GST_peer_list_size) || (NULL == GST_peer_list[peer_id]))
1795 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1797 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1800 peer = GST_peer_list[peer_id];
1801 if (GNUNET_YES == peer->is_remote)
1803 struct ForwardedOperationContext *fopc;
1805 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", peer_id);
1806 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1807 GNUNET_SERVER_client_keep (client);
1808 fopc->client = client;
1809 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1810 fopc->type = OP_PEER_INFO;
1812 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1814 fopc->operation_id, &msg->header,
1815 &GST_forwarded_operation_reply_relay,
1817 fopc->timeout_task =
1818 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &GST_forwarded_operation_timeout,
1820 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1821 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1824 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", peer_id);
1826 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg,
1828 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
1829 GNUNET_free (config);
1832 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1833 reply = GNUNET_realloc (xconfig, msize);
1834 (void) memmove (&reply[1], reply, xc_size);
1835 reply->header.size = htons (msize);
1836 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION);
1837 reply->peer_id = msg->peer_id;
1838 reply->operation_id = msg->operation_id;
1839 GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer,
1840 &reply->peer_identity);
1841 reply->config_size = htons ((uint16_t) c_size);
1842 GST_queue_message (client, &reply->header);
1843 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1848 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
1851 * @param client identification of the client
1852 * @param message the actual message
1855 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1856 const struct GNUNET_MessageHeader *message)
1858 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
1859 struct Slave *slave;
1860 struct GNUNET_TESTBED_SlaveConfiguration *reply;
1864 size_t xconfig_size;
1869 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
1870 slave_id = ntohl (msg->slave_id);
1871 op_id = GNUNET_ntohll (msg->operation_id);
1872 if ((GST_slave_list_size <= slave_id) || (NULL == GST_slave_list[slave_id]))
1874 /* FIXME: Add forwardings for this type of message here.. */
1875 GST_send_operation_fail_msg (client, op_id, "Slave not found");
1876 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1879 slave = GST_slave_list[slave_id];
1880 if (NULL == slave->cfg)
1882 GST_send_operation_fail_msg (client, op_id,
1883 "Configuration not found (slave not started by me)");
1884 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1887 config = GNUNET_CONFIGURATION_serialize (slave->cfg, &config_size);
1889 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
1890 GNUNET_free (config);
1891 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
1892 GNUNET_break (reply_size <= UINT16_MAX);
1893 GNUNET_break (config_size <= UINT16_MAX);
1894 reply = GNUNET_realloc (xconfig, reply_size);
1895 (void) memmove (&reply[1], reply, xconfig_size);
1896 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION);
1897 reply->header.size = htons ((uint16_t) reply_size);
1898 reply->slave_id = msg->slave_id;
1899 reply->operation_id = msg->operation_id;
1900 reply->config_size = htons ((uint16_t) config_size);
1901 GST_queue_message (client, &reply->header);
1902 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1907 * Iterator over hash map entries.
1909 * @param cls closure
1910 * @param key current key code
1911 * @param value value in the hash map
1912 * @return GNUNET_YES if we should continue to
1917 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1919 struct SharedService *ss = value;
1921 GNUNET_assert (GNUNET_YES ==
1922 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
1923 GNUNET_free (ss->name);
1930 * Iterator for freeing hash map entries in a slave's reghost_map
1932 * @param cls handle to the slave
1933 * @param key current key code
1934 * @param value value in the hash map
1935 * @return GNUNET_YES if we should continue to
1940 reghost_free_iterator (void *cls, const struct GNUNET_HashCode *key,
1943 struct Slave *slave = cls;
1944 struct RegisteredHostContext *rhc = value;
1945 struct ForwardedOverlayConnectContext *focc;
1947 GNUNET_assert (GNUNET_YES ==
1948 GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key,
1950 while (NULL != (focc = rhc->focc_dll_head))
1952 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc);
1953 GST_cleanup_focc (focc);
1955 if (NULL != rhc->sub_op)
1956 GNUNET_TESTBED_operation_done (rhc->sub_op);
1957 if (NULL != rhc->client)
1958 GNUNET_SERVER_client_drop (rhc->client);
1959 GNUNET_free (value);
1965 * Task to clean up and shutdown nicely
1968 * @param tc the TaskContext from scheduler
1971 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1973 struct LCFContextQueue *lcfq;
1974 struct ForwardedOperationContext *fopc;
1975 struct MessageQueue *mq_entry;
1978 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
1979 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
1980 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
1982 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
1983 /* cleanup any remaining forwarded operations */
1984 while (NULL != (fopc = fopcq_head))
1986 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
1987 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
1988 if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
1989 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
1990 GNUNET_SERVER_client_drop (fopc->client);
1993 case OP_PEER_CREATE:
1994 GNUNET_free (fopc->cls);
1998 case OP_PEER_DESTROY:
2000 case OP_OVERLAY_CONNECT:
2001 case OP_LINK_CONTROLLERS:
2002 case OP_GET_SLAVE_CONFIG:
2009 if (NULL != lcfq_head)
2011 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
2013 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
2014 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
2017 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
2018 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
2020 GNUNET_free (lcfq->lcf->msg);
2021 GNUNET_free (lcfq->lcf);
2022 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
2027 /* Clear peer list */
2028 for (id = 0; id < GST_peer_list_size; id++)
2029 if (NULL != GST_peer_list[id])
2031 /* If destroy flag is set it means that this peer should have been
2032 * destroyed by a context which we destroy before */
2033 GNUNET_break (GNUNET_NO == GST_peer_list[id]->destroy_flag);
2034 /* counter should be zero as we free all contexts before */
2035 GNUNET_break (0 == GST_peer_list[id]->reference_cnt);
2036 if ((GNUNET_NO == GST_peer_list[id]->is_remote) &&
2037 (GNUNET_YES == GST_peer_list[id]->details.local.is_running))
2038 GNUNET_TESTING_peer_kill (GST_peer_list[id]->details.local.peer);
2040 for (id = 0; id < GST_peer_list_size; id++)
2041 if (NULL != GST_peer_list[id])
2043 if (GNUNET_NO == GST_peer_list[id]->is_remote)
2045 if (GNUNET_YES == GST_peer_list[id]->details.local.is_running)
2046 GNUNET_TESTING_peer_wait (GST_peer_list[id]->details.local.peer);
2047 GNUNET_TESTING_peer_destroy (GST_peer_list[id]->details.local.peer);
2048 GNUNET_CONFIGURATION_destroy (GST_peer_list[id]->details.local.cfg);
2050 GNUNET_free (GST_peer_list[id]);
2052 GNUNET_free_non_null (GST_peer_list);
2053 /* Clear host list */
2054 for (id = 0; id < GST_host_list_size; id++)
2055 if (NULL != GST_host_list[id])
2056 GNUNET_TESTBED_host_destroy (GST_host_list[id]);
2057 GNUNET_free_non_null (GST_host_list);
2058 /* Clear route list */
2059 for (id = 0; id < route_list_size; id++)
2060 if (NULL != route_list[id])
2061 GNUNET_free (route_list[id]);
2062 GNUNET_free_non_null (route_list);
2063 /* Clear GST_slave_list */
2064 for (id = 0; id < GST_slave_list_size; id++)
2065 if (NULL != GST_slave_list[id])
2067 struct HostRegistration *hr_entry;
2069 while (NULL != (hr_entry = GST_slave_list[id]->hr_dll_head))
2071 GNUNET_CONTAINER_DLL_remove (GST_slave_list[id]->hr_dll_head,
2072 GST_slave_list[id]->hr_dll_tail, hr_entry);
2073 GNUNET_free (hr_entry);
2075 if (NULL != GST_slave_list[id]->rhandle)
2076 GNUNET_TESTBED_cancel_registration (GST_slave_list[id]->rhandle);
2078 GNUNET_CONTAINER_multihashmap_iterate (GST_slave_list
2080 reghost_free_iterator,
2081 GST_slave_list[id]);
2082 GNUNET_CONTAINER_multihashmap_destroy (GST_slave_list[id]->reghost_map);
2083 if (NULL != GST_slave_list[id]->cfg)
2084 GNUNET_CONFIGURATION_destroy (GST_slave_list[id]->cfg);
2085 if (NULL != GST_slave_list[id]->controller)
2086 GNUNET_TESTBED_controller_disconnect (GST_slave_list[id]->controller);
2087 if (NULL != GST_slave_list[id]->controller_proc)
2088 GNUNET_TESTBED_controller_stop (GST_slave_list[id]->controller_proc);
2089 GNUNET_free (GST_slave_list[id]);
2091 GNUNET_free_non_null (GST_slave_list);
2092 if (NULL != GST_context)
2094 GNUNET_free_non_null (GST_context->master_ip);
2095 if (NULL != GST_context->system)
2096 GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
2097 GNUNET_SERVER_client_drop (GST_context->client);
2098 GNUNET_free (GST_context);
2101 if (NULL != transmit_handle)
2102 GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle);
2103 while (NULL != (mq_entry = mq_head))
2105 GNUNET_free (mq_entry->msg);
2106 GNUNET_SERVER_client_drop (mq_entry->client);
2107 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
2108 GNUNET_free (mq_entry);
2110 GNUNET_free_non_null (hostname);
2111 GNUNET_CONFIGURATION_destroy (our_config);
2112 /* Free hello cache */
2114 GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
2115 GST_opq_openfds = NULL;
2120 * Callback for client disconnect
2123 * @param client the client which has disconnected
2126 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
2128 if (NULL == GST_context)
2130 if (client == GST_context->client)
2132 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
2133 /* should not be needed as we're terminated by failure to read
2134 * from stdin, but if stdin fails for some reason, this shouldn't
2135 * hurt for now --- might need to revise this later if we ever
2136 * decide that master connections might be temporarily down
2137 * for some reason */
2138 //GNUNET_SCHEDULER_shutdown ();
2146 * @param cls closure
2147 * @param server the initialized server
2148 * @param cfg configuration to use
2151 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
2152 const struct GNUNET_CONFIGURATION_Handle *cfg)
2154 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
2155 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
2156 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
2157 {&handle_configure_shared_service, NULL,
2158 GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE, 0},
2159 {&handle_link_controllers, NULL,
2160 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, 0},
2161 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, 0},
2162 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER,
2163 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
2164 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER,
2165 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
2166 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER,
2167 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
2168 {&handle_peer_get_config, NULL,
2169 GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION,
2170 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
2171 {&GST_handle_overlay_connect, NULL,
2172 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT,
2173 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
2174 {&GST_handle_remote_overlay_connect, NULL,
2175 GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, 0},
2176 {handle_slave_get_config, NULL,
2177 GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION,
2178 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
2182 unsigned long long num;
2185 GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
2188 GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile));
2189 GNUNET_free (logfile);
2191 GNUNET_assert (GNUNET_OK ==
2192 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2195 GST_cache_init ((unsigned int) num);
2196 GNUNET_assert (GNUNET_OK ==
2197 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
2198 "MAX_OPEN_FDS", &num));
2199 GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ ((unsigned int) num);
2200 GNUNET_assert (GNUNET_OK ==
2201 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
2202 "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);
2208 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
2209 GNUNET_SCHEDULER_PRIORITY_IDLE,
2210 &shutdown_task, NULL);
2211 LOG_DEBUG ("Testbed startup complete\n");
2212 event_mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
2217 * The starting point of execution
2220 main (int argc, char *const *argv)
2222 //sleep (15); /* Debugging */
2223 return (GNUNET_OK ==
2224 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
2225 &testbed_run, NULL)) ? 0 : 1;
2228 /* end of gnunet-service-testbed.c */