-controller startup, connect and duals
[oweals/gnunet.git] / src / testbed / testbed_api.c
1 /*
2       This file is part of GNUnet
3       (C) 2008--2012 Christian Grothoff (and other contributing authors)
4
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 3, or (at your
8       option) any later version.
9
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.
14
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.
19  */
20
21 /**
22  * @file testbed/testbed_api.c
23  * @brief API for accessing the GNUnet testing service.
24  *        This library is supposed to make it easier to write
25  *        testcases and script large-scale benchmarks.
26  * @author Christian Grothoff
27  */
28 #include "platform.h"
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_core_service.h"
31 #include "gnunet_constants.h"
32 #include "gnunet_transport_service.h"
33 #include "gnunet_hello_lib.h"
34 #include <zlib.h>
35
36 #include "testbed.h"
37 #include "testbed_api_hosts.h"
38
39 /**
40  * Generic logging shorthand
41  */
42 #define LOG(kind, ...)                          \
43   GNUNET_log_from (kind, "testbed-api", __VA_ARGS__);
44
45 /**
46  * Debug logging
47  */
48 #define LOG_DEBUG(...)                          \
49   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
50
51
52 /**
53  * The message queue for sending messages to the controller service
54  */
55 struct MessageQueue
56 {
57   /**
58    * The message to be sent
59    */
60   struct GNUNET_MessageHeader *msg;
61
62   /**
63    * next pointer for DLL
64    */
65   struct MessageQueue *next;
66   
67   /**
68    * prev pointer for DLL
69    */
70   struct MessageQueue *prev;
71 };
72
73
74 /**
75  * Structure for a controller link
76  */
77 struct ControllerLink
78 {
79   /**
80    * The next ptr for DLL
81    */
82   struct ControllerLink *next;
83
84   /**
85    * The prev ptr for DLL
86    */
87   struct ControllerLink *prev;
88
89   /**
90    * The host which will be referred in the peer start request. This is the
91    * host where the peer should be started
92    */
93   struct GNUNET_TESTBED_Host *delegated_host;
94
95   /**
96    * The host which will contacted to delegate the peer start request
97    */
98   struct GNUNET_TESTBED_Host *slave_host;
99
100   /**
101    * The configuration to be used to connect to slave host
102    */
103   const struct GNUNET_CONFIGURATION_Handle *slave_cfg;
104
105   /**
106    * GNUNET_YES if the slave should be started (and stopped) by us; GNUNET_NO
107    * if we are just allowed to use the slave via TCP/IP
108    */
109   int is_subordinate;
110 };
111
112
113 /**
114  * Handle to interact with a GNUnet testbed controller.  Each
115  * controller has at least one master handle which is created when the
116  * controller is created; this master handle interacts with the
117  * controller process, destroying it destroys the controller (by
118  * closing stdin of the controller process).  Additionally,
119  * controllers can interact with each other (in a P2P fashion); those
120  * links are established via TCP/IP on the controller's service port.
121  */
122 struct GNUNET_TESTBED_Controller
123 {
124
125   /**
126    * The host where the controller is running
127    */
128   struct GNUNET_TESTBED_Host *host;
129
130   /**
131    * The controller callback
132    */
133   GNUNET_TESTBED_ControllerCallback cc;
134
135   /**
136    * The closure for controller callback
137    */
138   void *cc_cls;
139
140   /**
141    * The configuration to use while connecting to controller
142    */
143   struct GNUNET_CONFIGURATION_Handle *cfg;
144
145   /**
146    * The client connection handle to the controller service
147    */
148   struct GNUNET_CLIENT_Connection *client;
149   
150   /**
151    * The head of the message queue
152    */
153   struct MessageQueue *mq_head;
154
155   /**
156    * The tail of the message queue
157    */
158   struct MessageQueue *mq_tail;
159
160   /**
161    * The head of the ControllerLink list
162    */
163   struct ControllerLink *cl_head;
164
165   /**
166    * The tail of the ControllerLink list
167    */
168   struct ControllerLink *cl_tail;
169
170   /**
171    * The client transmit handle
172    */
173   struct GNUNET_CLIENT_TransmitHandle *th;
174
175   /**
176    * The host registration handle; NULL if no current registration requests are
177    * present 
178    */
179   struct GNUNET_TESTBED_HostRegistrationHandle *rh;
180
181   /**
182    * The controller event mask
183    */
184   uint64_t event_mask;
185
186   /**
187    * Did we start the receive loop yet?
188    */
189   int in_receive;
190
191   /**
192    * Did we create the host for this?
193    */
194   int aux_host;
195 };
196
197
198 /**
199  * handle for host registration
200  */
201 struct GNUNET_TESTBED_HostRegistrationHandle
202 {
203   /**
204    * The host being registered
205    */
206   struct GNUNET_TESTBED_Host *host;
207
208   /**
209    * The controller at which this host is being registered
210    */
211   struct GNUNET_TESTBED_Controller *c;
212
213   /**
214    * The Registartion completion callback
215    */
216   GNUNET_TESTBED_HostRegistrationCompletion cc;
217
218   /**
219    * The closure for above callback
220    */
221   void *cc_cls;
222 };
223
224
225 /**
226  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
227  * controller (testbed service)
228  *
229  * @param c the controller handler
230  * @param msg message received
231  * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
232  *           not
233  */
234 static int
235 handle_addhostconfirm (struct GNUNET_TESTBED_Controller *c,
236                        const struct GNUNET_TESTBED_HostConfirmedMessage *msg)
237 {
238   struct GNUNET_TESTBED_HostRegistrationHandle *rh;
239   char *emsg;
240   uint16_t msg_size;
241
242   rh = c->rh;
243   if (NULL == rh)
244   {  
245     return GNUNET_OK;    
246   }
247   if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
248   {
249     LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n",
250                GNUNET_TESTBED_host_get_id_ (rh->host), ntohl (msg->host_id));
251     return GNUNET_OK;
252   }
253   c->rh = NULL;
254   msg_size = ntohs (msg->header.size);
255   if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size)
256   {
257     LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id));
258     GNUNET_TESTBED_mark_host_registered_at_  (rh->host, c);
259     rh->cc (rh->cc_cls, NULL);
260     GNUNET_free (rh);
261     return GNUNET_OK;
262   } 
263   /* We have an error message */
264   emsg = (char *) &msg[1];
265   if ('\0' != emsg[msg_size - 
266                    sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)])
267   {
268     GNUNET_break (0);
269     GNUNET_free (rh);
270     return GNUNET_NO;
271   }  
272   LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"),
273        ntohl (msg->host_id), emsg);
274   rh->cc (rh->cc_cls, emsg);
275   GNUNET_free (rh);
276   return GNUNET_OK;
277 }
278
279
280 /**
281  * Handler for messages from controller (testbed service)
282  *
283  * @param cls the controller handler
284  * @param msg message received, NULL on timeout or fatal error
285  */
286 static void 
287 message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
288 {
289   struct GNUNET_TESTBED_Controller *c = cls;  
290   int status;
291
292   /* FIXME: Add checks for message integrity */
293   if (NULL == msg)
294   {
295     LOG_DEBUG ("Receive timed out or connection to service dropped\n");
296     return;
297   }
298   status = GNUNET_OK;
299   switch (ntohs (msg->type))
300   {
301   case GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM:
302     status =
303       handle_addhostconfirm (c, (const struct
304                                  GNUNET_TESTBED_HostConfirmedMessage *) msg);   
305     break;
306   default:
307     GNUNET_break (0);
308   }
309   if (GNUNET_OK == status)
310     GNUNET_CLIENT_receive (c->client, &message_handler, c,
311                            GNUNET_TIME_UNIT_FOREVER_REL);
312 }
313
314
315 /**
316  * Function called to notify a client about the connection begin ready to queue
317  * more data.  "buf" will be NULL and "size" zero if the connection was closed
318  * for writing in the meantime.
319  *
320  * @param cls closure
321  * @param size number of bytes available in buf
322  * @param buf where the callee should write the message
323  * @return number of bytes written to buf
324  */
325 static size_t
326 transmit_ready_notify (void *cls, size_t size, void *buf)
327 {
328   struct GNUNET_TESTBED_Controller *c = cls;
329   struct MessageQueue *mq_entry;
330
331   c->th = NULL;
332   mq_entry = c->mq_head;
333   GNUNET_assert (NULL != mq_entry);
334   GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
335   size = ntohs (mq_entry->msg->size);
336   memcpy (buf, mq_entry->msg, size);
337   GNUNET_free (mq_entry->msg);
338   GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, mq_entry);
339   GNUNET_free (mq_entry);
340   mq_entry = c->mq_head;
341   if (NULL != mq_entry)
342     c->th = 
343       GNUNET_CLIENT_notify_transmit_ready (c->client,
344                                            ntohs (mq_entry->msg->size),
345                                            GNUNET_TIME_UNIT_FOREVER_REL,
346                                            GNUNET_NO, &transmit_ready_notify,
347                                            c);
348   if ( (GNUNET_NO == c->in_receive) &&
349        (size > 0) )
350   {
351     c->in_receive = GNUNET_YES;
352     GNUNET_CLIENT_receive (c->client, &message_handler, c,
353                            GNUNET_TIME_UNIT_FOREVER_REL);
354   }
355   return size;
356 }
357
358
359 /**
360  * Queues a message in send queue for sending to the service
361  *
362  * @param controller the handle to the controller
363  * @param msg the message to queue
364  */
365 static void
366 queue_message (struct GNUNET_TESTBED_Controller *controller,
367                struct GNUNET_MessageHeader *msg)
368 {
369   struct MessageQueue *mq_entry;
370   uint16_t type;
371   uint16_t size;
372
373   type = ntohs (msg->type);
374   size = ntohs (msg->size);
375   GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
376                  (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));                 
377   mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
378   mq_entry->msg = msg;
379   LOG (GNUNET_ERROR_TYPE_DEBUG,
380        "Queueing message of type %u, size %u for sending\n", type,
381        ntohs (msg->size));
382   GNUNET_CONTAINER_DLL_insert_tail (controller->mq_head, controller->mq_tail,
383                                     mq_entry);
384   if (NULL == controller->th)
385     controller->th = 
386       GNUNET_CLIENT_notify_transmit_ready (controller->client, size,
387                                            GNUNET_TIME_UNIT_FOREVER_REL,
388                                            GNUNET_NO, &transmit_ready_notify,
389                                            controller);
390 }
391
392
393 /**
394  * Handle for controller process
395  */
396 struct GNUNET_TESTBED_ControllerProc
397 {
398   /**
399    * The helper handle
400    */
401   struct GNUNET_TESTBED_HelperHandle *helper;
402
403 };
404
405
406 /**
407  * Starts a controller process at the host
408  *
409  * @param host the host where the controller has to be started; NULL for localhost
410  * @return the controller process handle
411  */
412 struct GNUNET_TESTBED_ControllerProc *
413 GNUNET_TESTBED_controller_start (struct GNUNET_TESTBED_Host *host)
414 {
415   struct GNUNET_TESTBED_ControllerProc *cproc;
416   char * const binary_argv[] = {
417     "gnunet-service-testbed",
418     "gnunet-service-testbed",
419     NULL
420   };
421
422   cproc = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc));
423   cproc->helper = GNUNET_TESTBED_host_run_ (host, binary_argv);
424   if (NULL == cproc->helper)
425   {
426     GNUNET_free (cproc);
427     return NULL;
428   }
429   return cproc;
430 }
431
432
433 /**
434  * Stop the controller process (also will terminate all peers and controllers
435  * dependent on this controller).  This function blocks until the testbed has
436  * been fully terminated (!).
437  *
438  * @param cproc the controller process handle
439  */
440 void
441 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc)
442 {
443   GNUNET_TESTBED_host_stop_ (cproc->helper);
444   GNUNET_free (cproc);
445 }
446
447
448 /**
449  * Start a controller process using the given configuration at the
450  * given host.
451  *
452  * @param cfg configuration to use
453  * @param host host to run the controller on; This should be the same host if
454  *          the controller was previously started with
455  *          GNUNET_TESTBED_controller_start; NULL for localhost
456  * @param event_mask bit mask with set of events to call 'cc' for;
457  *                   or-ed values of "1LL" shifted by the
458  *                   respective 'enum GNUNET_TESTBED_EventType'
459  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
460  * @param cc controller callback to invoke on events
461  * @param cc_cls closure for cc
462  * @return handle to the controller
463  */
464 struct GNUNET_TESTBED_Controller *
465 GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
466                                    struct GNUNET_TESTBED_Host *host,
467                                    uint64_t event_mask,
468                                    GNUNET_TESTBED_ControllerCallback cc,
469                                    void *cc_cls)
470 {
471   struct GNUNET_TESTBED_Controller *controller;
472   struct GNUNET_TESTBED_InitMessage *msg;
473
474   controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller));
475   controller->cc = cc;
476   controller->cc_cls = cc_cls;
477   controller->event_mask = event_mask;
478   controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
479   controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg);  
480   if (NULL == controller->client)
481   {
482     GNUNET_TESTBED_controller_disconnect (controller);
483     return NULL;
484   }
485   if (NULL == host)
486   {
487     host = GNUNET_TESTBED_host_create_by_id_ (0);
488     if (NULL == host)
489     {
490       LOG (GNUNET_ERROR_TYPE_WARNING,
491            "Treating NULL host as localhost. Multiple references to localhost. "
492            " May break when localhost freed before calling disconnect \n");
493       host = GNUNET_TESTBED_host_lookup_by_id_ (0);
494     }
495     else
496     {
497       controller->aux_host = GNUNET_YES;
498     }
499   }
500   GNUNET_assert (NULL != host);
501   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage));
502   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
503   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage));
504   msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
505   msg->event_mask = GNUNET_htonll (controller->event_mask);
506   queue_message (controller, (struct GNUNET_MessageHeader *) msg);
507   return controller;
508 }
509
510
511 /**
512  * Configure shared services at a controller.  Using this function,
513  * you can specify that certain services (such as "resolver")
514  * should not be run for each peer but instead be shared
515  * across N peers on the specified host.  This function
516  * must be called before any peers are created at the host.
517  * 
518  * @param controller controller to configure
519  * @param service_name name of the service to share
520  * @param num_peers number of peers that should share one instance
521  *        of the specified service (1 for no sharing is the default),
522  *        use 0 to disable the service
523  */
524 void
525 GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
526                                              const char *service_name,
527                                              uint32_t num_peers)
528 {
529   struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
530   uint16_t service_name_size;
531   uint16_t msg_size;
532   
533   service_name_size = strlen (service_name) + 1;
534   msg_size = sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage)
535     + service_name_size;
536   msg = GNUNET_malloc (msg_size);
537   msg->header.size = htons (msg_size);
538   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE);
539   msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host));
540   msg->num_peers = htonl (num_peers);
541   memcpy (&msg[1], service_name, service_name_size);
542   queue_message (controller, (struct GNUNET_MessageHeader *) msg);
543 }
544
545
546 /**
547  * disconnects from the controller.
548  *
549  * @param controller handle to controller to stop
550  */
551 void
552 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller)
553 {
554   struct MessageQueue *mq_entry;
555
556   if (NULL != controller->th)
557     GNUNET_CLIENT_notify_transmit_ready_cancel (controller->th);
558  /* Clear the message queue */
559   while (NULL != (mq_entry = controller->mq_head))
560   {
561     GNUNET_CONTAINER_DLL_remove (controller->mq_head,
562                                  controller->mq_tail,
563                                  mq_entry);
564     GNUNET_free (mq_entry->msg);
565     GNUNET_free (mq_entry);
566   }
567   if (NULL != controller->client)
568     GNUNET_CLIENT_disconnect (controller->client);
569   GNUNET_CONFIGURATION_destroy (controller->cfg);
570   if (GNUNET_YES == controller->aux_host)
571     GNUNET_TESTBED_host_destroy (controller->host);
572   GNUNET_free (controller);
573 }
574
575
576 /**
577  * Register a host with the controller
578  *
579  * @param controller the controller handle
580  * @param host the host to register
581  * @param cc the completion callback to call to inform the status of
582  *          registration. After calling this callback the registration handle
583  *          will be invalid. Cannot be NULL.
584  * @param cc_cls the closure for the cc
585  * @return handle to the host registration which can be used to cancel the
586  *           registration 
587  */
588 struct GNUNET_TESTBED_HostRegistrationHandle *
589 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
590                               struct GNUNET_TESTBED_Host *host,
591                               GNUNET_TESTBED_HostRegistrationCompletion cc,
592                               void *cc_cls)
593 {
594   struct GNUNET_TESTBED_HostRegistrationHandle *rh;
595   struct GNUNET_TESTBED_AddHostMessage *msg;
596   const char *username;
597   const char *hostname;
598   uint16_t msg_size;
599   uint16_t user_name_length;
600
601   if (NULL != controller->rh)
602     return NULL;
603   hostname = GNUNET_TESTBED_host_get_hostname_ (host);
604   if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller))
605   {
606     LOG (GNUNET_ERROR_TYPE_WARNING,
607          "Host hostname: %s already registered\n",
608          (NULL == hostname) ? "localhost" : hostname);
609     return NULL;
610   }  
611   rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle));
612   rh->host = host;
613   rh->c = controller;
614   GNUNET_assert (NULL != cc);
615   rh->cc = cc;
616   rh->cc_cls = cc_cls;
617   controller->rh = rh;
618   username = GNUNET_TESTBED_host_get_username_ (host);
619   msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage));
620   user_name_length = 0;
621   if (NULL != username)
622   {
623     user_name_length = strlen (username) + 1;
624     msg_size += user_name_length;
625   }
626   /* FIXME: what happens when hostname is NULL? localhost */
627   GNUNET_assert (NULL != hostname);
628   msg_size += strlen (hostname) + 1;
629   msg = GNUNET_malloc (msg_size);
630   msg->header.size = htons (msg_size);
631   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST);
632   msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
633   msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host));
634   msg->user_name_length = htons (user_name_length);
635   if (NULL != username)
636     memcpy (&msg[1], username, user_name_length);
637   strcpy (((void *) msg) + user_name_length, hostname);
638   queue_message (controller, (struct GNUNET_MessageHeader *) msg);
639   return rh;
640 }
641
642
643 /**
644  * Cancel the pending registration. Note that if the registration message is
645  * already sent to the service the cancellation has only the effect that the
646  * registration completion callback for the registration is never called.
647  *
648  * @param handle the registration handle to cancel
649  */
650 void
651 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
652                                     *handle)
653 {
654   if (handle != handle->c->rh)
655   {
656     GNUNET_break (0);
657     return;
658   }
659   handle->c->rh = NULL;
660   GNUNET_free (handle);  
661 }
662
663
664 /**
665  * Create a link from a 'master' controller to a slave controller.
666  * Whenever the master controller is asked to start a peer at the
667  * given 'delegated_host', it will delegate the request to the
668  * specified slave controller.  Note that the slave controller runs at
669  * the 'slave_host', which may or may not be the same host as the
670  * 'delegated_host' (for hierarchical delegations).  The configuration
671  * of the slave controller is given and to be used to either create
672  * the slave controller or to connect to an existing slave controller
673  * process.  'is_subordinate' specifies if the given slave controller
674  * should be started and managed by the master controller, or if the
675  * slave already has a master and this is just a secondary master that
676  * is also allowed to use the existing slave.
677  *
678  * @param master handle to the master controller who creates the association
679  * @param delegated_host requests to which host should be delegated
680  * @param slave_host which host is used to run the slave controller 
681  * @param slave_cfg configuration to use for the slave controller
682  * @param is_subordinate GNUNET_YES if the slave should be started (and stopped)
683  *                       by the master controller; GNUNET_NO if we are just
684  *                       allowed to use the slave via TCP/IP
685  */
686 void
687 GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
688                                 struct GNUNET_TESTBED_Host *delegated_host,
689                                 struct GNUNET_TESTBED_Host *slave_host,
690                                 const struct GNUNET_CONFIGURATION_Handle *slave_cfg,
691                                 int is_subordinate)
692 {
693   struct GNUNET_TESTBED_ControllerLinkMessage *msg;
694   char *config;
695   Bytef *cconfig;
696   uLongf cc_size;
697   size_t config_size;  
698   uint16_t msg_size;
699
700   GNUNET_assert (GNUNET_YES == 
701                  GNUNET_TESTBED_is_host_registered_ (delegated_host, master));
702   GNUNET_assert (GNUNET_YES == 
703                  GNUNET_TESTBED_is_host_registered_ (slave_host, master));
704   config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size);
705   cc_size = compressBound ((uLong) config_size);
706   cconfig = GNUNET_malloc (cc_size);
707   GNUNET_assert (Z_OK ==
708                  compress2 (cconfig, &cc_size, 
709                             (Bytef *) config, config_size, Z_BEST_SPEED));
710   GNUNET_free (config);
711   GNUNET_assert ((UINT16_MAX -
712                   sizeof (struct GNUNET_TESTBED_ControllerLinkMessage))
713                   >= cc_size); /* Configuration doesn't fit in 1 message */
714   msg_size = cc_size + sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
715   msg = GNUNET_realloc (cconfig, msg_size);
716   memmove (msg + sizeof (struct GNUNET_TESTBED_ControllerLinkMessage),
717            msg, cc_size);
718   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS);
719   msg->header.size = htons (msg_size);
720   msg->delegated_host_id = htonl (GNUNET_TESTBED_host_get_id_ (delegated_host));
721   msg->slave_host_id = htonl (GNUNET_TESTBED_host_get_id_ (slave_host));
722   msg->config_size = htons ((uint16_t) config_size);
723   msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0;
724   queue_message (master, (struct GNUNET_MessageHeader *) msg);
725 }
726
727
728 /**
729  * Ask the testbed controller to write the current overlay topology to
730  * a file.  Naturally, the file will only contain a snapshot as the
731  * topology may evolve all the time.
732  *
733  * @param controller overlay controller to inspect
734  * @param filename name of the file the topology should
735  *        be written to.
736  */
737 void
738 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
739                                                const char *filename)
740 {
741   GNUNET_break (0);
742 }
743
744
745
746 /* end of testbed_api.c */