fixes for controller_start() API changes
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed.c
1 /*
2   This file is part of GNUnet.
3   (C) 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 2, 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/gnunet-service-testbed.c
23  * @brief implementation of the TESTBED service
24  * @author Sree Harsha Totakura
25  */
26
27 #include "platform.h"
28 #include "gnunet_service_lib.h"
29 #include "gnunet_server_lib.h"
30 #include <zlib.h>
31
32 #include "testbed.h"
33 #include "gnunet_testbed_service.h"
34 #include "testbed_api_hosts.h"
35 #include "gnunet_testing_lib-new.h"
36
37 /**
38  * Generic logging
39  */
40 #define LOG(kind,...)                           \
41   GNUNET_log (kind, __VA_ARGS__)
42
43 /**
44  * Debug logging
45  */
46 #define LOG_DEBUG(...)                          \
47   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
48
49
50 #define LIST_GROW_STEP 10
51
52 struct Context
53 {
54   /**
55    * The client handle associated with this context
56    */
57   struct GNUNET_SERVER_Client *client;
58   
59   /**
60    * Event mask of event to be responded in this context
61    */
62   uint64_t event_mask;
63
64   /**
65    * Our host id according to this context
66    */
67   uint32_t host_id;
68 };
69
70
71 /**
72  * The message queue for sending messages to clients
73  */
74 struct MessageQueue
75 {
76   /**
77    * The message to be sent
78    */
79   struct GNUNET_MessageHeader *msg;
80
81   /**
82    * The client to send the message to
83    */
84   struct GNUNET_SERVER_Client *client;
85   
86   /**
87    * next pointer for DLL
88    */
89   struct MessageQueue *next;
90   
91   /**
92    * prev pointer for DLL
93    */
94   struct MessageQueue *prev;
95 };
96
97
98 /**
99  * The structure for identifying a shared service
100  */
101 struct SharedService
102 {
103   /**
104    * The name of the shared service
105    */
106   char *name;
107
108   /**
109    * Number of shared peers per instance of the shared service
110    */
111   uint32_t num_shared;
112
113   /**
114    * Number of peers currently sharing the service
115    */
116   uint32_t num_sharing;
117 };
118
119
120 /**
121  * A routing entry
122  */
123 struct Route
124 {
125   /**
126    * destination host
127    */
128   uint32_t dest;
129
130   /**
131    * The host destination is reachable thru
132    */
133   uint32_t thru;
134 };
135
136
137 /**
138  * Structure representing a connected(directly-linked) controller
139  */
140 struct Slave
141 {
142   /**
143    * The controller process handle if we had started the controller
144    */
145   struct GNUNET_TESTBED_ControllerProc *controller_proc;
146
147   /**
148    * The controller handle
149    */
150   struct GNUNET_TESTBED_Controller *controller;
151
152   /**
153    * The id of the host this controller is running on
154    */
155   uint32_t host_id;
156 };
157
158
159 /**
160  * States of LCFContext
161  */
162 enum LCFContextState
163   {
164     /**
165      * The Context has been initialized; Nothing has been done on it
166      */
167     INIT,
168
169     /**
170      * Delegated host has been registered at the forwarding controller
171      */
172     DELEGATED_HOST_REGISTERED,
173     
174     /**
175      * The context has been finished (may have error)
176      */
177     FINISHED
178
179   };
180
181
182 /**
183  * Link controllers request forwarding context
184  */
185 struct LCFContext
186 {
187   /**
188    * The serialized and compressed configuration
189    */
190   char *sxcfg;
191
192   /**
193    * The gateway which will pass the link message to delegated host
194    */
195   struct Slave *gateway;
196
197   /**
198    * The host registration handle while registered hosts in this context
199    */
200   struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
201
202   /**
203    * The size of the compressed serialized configuration
204    */
205   size_t sxcfg_size;
206
207   /**
208    * The size of the uncompressed configuration
209    */
210   size_t scfg_size;
211
212   /**
213    * Should the delegated host be started by the slave host?
214    */
215   int is_subordinate;
216
217   /**
218    * The state of this context
219    */
220   enum LCFContextState state;
221
222   /**
223    * The delegated host
224    */
225   uint32_t delegated_host_id;
226   
227
228 };
229
230
231 /**
232  * Structure of a queue entry in LCFContext request queue
233  */
234 struct LCFContextQueue
235 {
236   /**
237    * The LCFContext
238    */
239   struct LCFContext *lcf;
240
241   /**
242    * Head prt for DLL
243    */
244   struct LCFContextQueue *next;
245
246   /**
247    * Tail ptr for DLL
248    */
249   struct LCFContextQueue *prev;
250 };
251
252
253 /**
254  * A locally started peer
255  */
256 struct Peer
257 {
258   /**
259    * The peer handle from testing API
260    */
261   struct GNUNET_TESTING_Peer *peer;
262
263   /**
264    * The modified (by GNUNET_TESTING_peer_configure) configuration this peer is
265    * configured with
266    */
267   struct GNUNET_CONFIGURATION_Handle *cfg;
268
269   /**
270    * Our local reference id for this peer
271    */
272   uint32_t id;
273
274 };
275
276
277 /**
278  * The master context; generated with the first INIT message
279  */
280 static struct Context *master_context;
281
282 /***********/
283 /* Handles */
284 /***********/
285
286 /**
287  * Wrapped stdin.
288  */
289 static struct GNUNET_DISK_FileHandle *fh;
290
291 /**
292  * Current Transmit Handle; NULL if no notify transmit exists currently
293  */
294 static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
295
296 /****************/
297 /* Lists & Maps */
298 /****************/
299
300 /**
301  * The head for the LCF queue
302  */
303 static struct LCFContextQueue *lcfq_head;
304
305 /**
306  * The tail for the LCF queue
307  */
308 static struct LCFContextQueue *lcfq_tail;
309
310 /**
311  * The message queue head
312  */
313 static struct MessageQueue *mq_head;
314
315 /**
316  * The message queue tail
317  */
318 static struct MessageQueue *mq_tail;
319
320 /**
321  * Array of host list
322  */
323 static struct GNUNET_TESTBED_Host **host_list;
324
325 /**
326  * A list of routes
327  */
328 static struct Route **route_list;
329
330 /**
331  * A list of directly linked neighbours
332  */
333 static struct Slave **slave_list;
334
335 /**
336  * A list of peers we own locally
337  */
338 static struct Peer **peer_list;
339
340 /**
341  * The hashmap of shared services
342  */
343 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
344
345 /**
346  * The size of the host list
347  */
348 static uint32_t host_list_size;
349
350 /**
351  * The size of the route list
352  */
353 static uint32_t route_list_size;
354
355 /**
356  * The size of directly linked neighbours list
357  */
358 static uint32_t slave_list_size;
359
360 /**
361  * The size of the peer list
362  */
363 static uint32_t peer_list_size;
364
365 /*********/
366 /* Tasks */
367 /*********/
368
369 /**
370  * The lcf_task handle
371  */
372 static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
373
374 /**
375  * The shutdown task handle
376  */
377 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
378
379 /******************/
380 /* Testing System */
381 /******************/
382
383 /**
384  * Handle to the local testing system - for starting peers locally
385  */
386 static struct GNUNET_TESTING_System *test_system;
387
388 /**
389  * Our configuration; we also use this as template for starting other controllers
390  */
391 static struct GNUNET_CONFIGURATION_Handle *config;
392
393
394 /**
395  * Function called to notify a client about the connection begin ready to queue
396  * more data.  "buf" will be NULL and "size" zero if the connection was closed
397  * for writing in the meantime.
398  *
399  * @param cls NULL
400  * @param size number of bytes available in buf
401  * @param buf where the callee should write the message
402  * @return number of bytes written to buf
403  */
404 static size_t
405 transmit_ready_notify (void *cls, size_t size, void *buf)
406 {
407   struct MessageQueue *mq_entry;
408
409   transmit_handle = NULL;
410   mq_entry = mq_head;
411   GNUNET_assert (NULL != mq_entry);
412   if (0 == size)
413     return 0;
414   GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
415   size = ntohs (mq_entry->msg->size);
416   memcpy (buf, mq_entry->msg, size);
417   GNUNET_free (mq_entry->msg);
418   GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
419   GNUNET_free (mq_entry);
420   mq_entry = mq_head;
421   if (NULL != mq_entry)
422     transmit_handle = 
423       GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
424                                            ntohs (mq_entry->msg->size),
425                                            GNUNET_TIME_UNIT_FOREVER_REL,
426                                            &transmit_ready_notify, NULL);
427   return size;
428 }
429
430
431 /**
432  * Queues a message in send queue for sending to the service
433  *
434  * @param client the client to whom the queued message has to be sent
435  * @param msg the message to queue
436  */
437 static void
438 queue_message (struct GNUNET_SERVER_Client *client,
439                struct GNUNET_MessageHeader *msg)
440 {
441   struct MessageQueue *mq_entry;
442   uint16_t type;
443   uint16_t size;
444
445   type = ntohs (msg->type);
446   size = ntohs (msg->size);
447   GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
448                  (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));                 
449   mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
450   mq_entry->msg = msg;
451   mq_entry->client = client;
452   LOG_DEBUG ( "Queueing message of type %u, size %u for sending\n", type,
453               ntohs (msg->size));
454   GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
455   if (NULL == transmit_handle)
456     transmit_handle = 
457       GNUNET_SERVER_notify_transmit_ready (client, size,
458                                            GNUNET_TIME_UNIT_FOREVER_REL,
459                                            &transmit_ready_notify, NULL);
460 }
461
462
463 /**
464  * Similar to GNUNET_realloc; however clears tail part of newly allocated memory
465  *
466  * @param ptr the memory block to realloc
467  * @param size the size of ptr
468  * @param new_size the size to which ptr has to be realloc'ed
469  * @return the newly reallocated memory block
470  */
471 static void *
472 TESTBED_realloc (void *ptr, size_t size, size_t new_size)
473 {
474   ptr = GNUNET_realloc (ptr, new_size);
475   if (new_size > size)
476     ptr = memset (ptr + size, 0, new_size - size);
477   return ptr;
478 }
479
480
481 /**
482  * Function to add a host to the current list of known hosts
483  *
484  * @param host the host to add 
485  * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
486  *           already in use
487  */
488 static int
489 host_list_add (struct GNUNET_TESTBED_Host *host)
490 {
491   uint32_t host_id;
492
493   host_id = GNUNET_TESTBED_host_get_id_ (host);
494   if (host_list_size <= host_id)
495   {
496     host_list = 
497       TESTBED_realloc (host_list, 
498                        sizeof (struct GNUNET_TESTBED_Host *) * host_list_size,
499                        sizeof (struct GNUNET_TESTBED_Host *) *
500                        (host_list_size + LIST_GROW_STEP));
501     host_list_size += LIST_GROW_STEP;
502   }
503   if (NULL != host_list[host_id])
504   {
505     LOG_DEBUG ("A host with id: %u already exists\n", host_id);
506     return GNUNET_SYSERR;
507   }
508   host_list[host_id] = host;
509   return GNUNET_OK;
510 }
511
512
513 /**
514  * Adds a route to the route list
515  *
516  * @param route the route to add
517  */
518 static void
519 route_list_add (struct Route *route)
520 {
521   if (route->dest >= route_list_size)
522   {
523     route_list = 
524       TESTBED_realloc (route_list, 
525                        sizeof (struct Route *) * route_list_size,
526                        sizeof (struct Route *) * 
527                        (route_list_size + LIST_GROW_STEP));
528     route_list_size += LIST_GROW_STEP;
529   }
530   GNUNET_assert (NULL == route_list[route->dest]);
531   route_list[route->dest] = route;
532 }
533
534
535 /**
536  * Adds a slave to the slave array
537  *
538  * @param route the route to add
539  */
540 static void
541 slave_list_add (struct Slave *slave)
542 {
543   if (slave->host_id  >= slave_list_size)
544   {
545     slave_list = TESTBED_realloc (slave_list, 
546                                   sizeof (struct Slave *) *slave_list_size,
547                                   sizeof (struct Slave *) *
548                                   (slave_list_size + LIST_GROW_STEP));
549     slave_list_size += LIST_GROW_STEP;
550   }
551   GNUNET_assert (NULL == slave_list[slave->host_id]);
552   slave_list[slave->host_id] = slave;
553 }
554
555
556 /**
557  * Adds a peer to the peer array
558  *
559  * @param route the route to add
560  */
561 static void
562 peer_list_add (struct Peer *peer)
563 {
564   if (peer->id  >= peer_list_size)
565   {
566     peer_list = TESTBED_realloc (peer_list, 
567                                  sizeof (struct Peer *) * peer_list_size,
568                                  sizeof (struct Peer *) *
569                                  (peer_list_size + LIST_GROW_STEP));
570     peer_list_size += LIST_GROW_STEP;
571   }
572   GNUNET_assert (NULL == peer_list[peer->id]);
573   peer_list[peer->id] = peer;
574 }
575
576
577 /**
578  * Routes message to a host given its host_id
579  *
580  * @param host_id the id of the destination host
581  * @param msg the message to be routed
582  */
583 static void
584 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
585 {
586   GNUNET_break (0);
587 }
588
589
590 /**
591  * The  Link Controller forwarding task
592  *
593  * @param cls the LCFContext
594  * @param tc the Task context from scheduler
595  */
596 static void
597 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
598
599
600 /**
601  * Completion callback for host registrations while forwarding Link Controller messages
602  *
603  * @param cls the LCFContext
604  * @param emsg the error message; NULL if host registration is successful
605  */
606 static void
607 lcf_proc_cc (void *cls, const char *emsg)
608 {
609   struct LCFContext *lcf = cls;
610
611   lcf->rhandle = NULL;
612   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
613   switch (lcf->state)
614   {
615   case INIT:
616     if (NULL != emsg)
617     {
618       LOG (GNUNET_ERROR_TYPE_WARNING, 
619            "Host registration failed with message: %s\n", emsg);
620       lcf->state = FINISHED;
621       lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
622       return;
623     }
624     lcf->state = DELEGATED_HOST_REGISTERED;
625     lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
626     break;
627   default:
628     GNUNET_assert (0);          /* Shouldn't reach here */
629   }  
630 }
631
632
633 /**
634  * The  Link Controller forwarding task
635  *
636  * @param cls the LCFContext
637  * @param tc the Task context from scheduler
638  */
639 static void
640 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
641 {
642   struct LCFContext *lcf = cls;
643   struct LCFContextQueue *lcfq;
644
645   lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
646   switch (lcf->state)
647   {
648   case INIT:
649     if (GNUNET_NO ==
650         GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id],
651                                             lcf->gateway->controller))
652     {
653       lcf->rhandle =
654         GNUNET_TESTBED_register_host (lcf->gateway->controller,
655                                       host_list[lcf->delegated_host_id],
656                                       lcf_proc_cc, lcf);                                                   
657     }
658     else
659     {
660       lcf->state = DELEGATED_HOST_REGISTERED;
661       lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
662     }
663     break;
664   case DELEGATED_HOST_REGISTERED:
665     GNUNET_TESTBED_controller_link_2 (lcf->gateway->controller,
666                                       host_list[lcf->delegated_host_id],
667                                       host_list[lcf->gateway->host_id],
668                                       lcf->sxcfg, lcf->sxcfg_size,
669                                       lcf->scfg_size,
670                                       lcf->is_subordinate);
671     lcf->state = FINISHED;
672   case FINISHED:   
673     lcfq = lcfq_head;
674     GNUNET_assert (lcfq->lcf == lcf);
675     GNUNET_free (lcf->sxcfg);
676     GNUNET_free (lcf);
677     GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
678     GNUNET_free (lcfq);
679     if (NULL != lcfq_head)
680       lcf_proc_task_id = 
681         GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
682   }
683 }
684
685
686 /**
687  * Callback for event from slave controllers
688  *
689  * @param cls struct Slave *
690  * @param event information about the event
691  */
692 static void 
693 slave_event_callback(void *cls,
694                      const struct GNUNET_TESTBED_EventInformation *event)
695 {
696   GNUNET_break (0);
697 }
698
699
700 /**
701  * Callback for unexpected slave shutdowns
702  *
703  * @param cls closure
704  * @param emsg error message if available; can be NULL, which does NOT mean
705  *             that there was no error
706  */
707 static void 
708 slave_shutdown_handler (void *cls, const char *emsg)
709 {
710   struct Slave *slave;
711
712   slave = (struct Slave *) cls;
713   slave->controller_proc = NULL;
714   LOG (GNUNET_ERROR_TYPE_WARNING,
715        "Unexpected slave shutdown\n");
716   if (NULL != emsg)
717     LOG (GNUNET_ERROR_TYPE_WARNING, "Error: %s\n", emsg);
718   GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
719 }
720
721
722 /**
723  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
724  *
725  * @param cls NULL
726  * @param client identification of the client
727  * @param message the actual message
728  */
729 static void 
730 handle_init (void *cls,
731              struct GNUNET_SERVER_Client *client,
732              const struct GNUNET_MessageHeader *message)
733 {
734   const struct GNUNET_TESTBED_InitMessage *msg;
735   struct GNUNET_TESTBED_Host *host;
736
737   if (NULL != master_context)
738   {
739     GNUNET_break (0);
740     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
741     return;
742   }
743   msg = (const struct GNUNET_TESTBED_InitMessage *) message;  
744   master_context = GNUNET_malloc (sizeof (struct Context));
745   master_context->client = client;
746   master_context->host_id = ntohl (msg->host_id);
747   host = GNUNET_TESTBED_host_create_with_id (master_context->host_id,
748                                              NULL, NULL, 0);
749   host_list_add (host);
750   master_context->event_mask = GNUNET_ntohll (msg->event_mask);
751   GNUNET_SERVER_client_keep (client);
752   LOG_DEBUG ("Created master context with host ID: %u\n",
753              master_context->host_id);
754   GNUNET_SERVER_receive_done (client, GNUNET_OK);
755 }
756
757
758 /**
759  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
760  *
761  * @param cls NULL
762  * @param client identification of the client
763  * @param message the actual message
764  */
765 static void 
766 handle_add_host (void *cls,
767                  struct GNUNET_SERVER_Client *client,
768                  const struct GNUNET_MessageHeader *message)
769 {
770   struct GNUNET_TESTBED_Host *host;
771   const struct GNUNET_TESTBED_AddHostMessage *msg;
772   struct GNUNET_TESTBED_HostConfirmedMessage *reply;
773   char *username;
774   char *hostname;
775   char *emsg;
776   uint32_t host_id;
777   uint16_t username_length;
778   uint16_t hostname_length;
779   uint16_t reply_size;
780   
781   msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
782   username_length = ntohs (msg->user_name_length);
783   username_length = (0 == username_length) ? 0 : username_length + 1;
784   username = (char *) &(msg[1]);
785   hostname = username + username_length;
786   if (ntohs (message->size) <=
787       (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length))
788   {
789     GNUNET_break (0);
790     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
791     return;
792   }
793   hostname_length = ntohs (message->size)
794     - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
795   if (strlen (hostname) != hostname_length - 1)
796   {
797     GNUNET_break (0);
798     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
799     return;
800   }
801   host_id = ntohl (msg->host_id);
802   LOG_DEBUG ("Received ADDHOST message\n");
803   LOG_DEBUG ("-------host id: %u\n", host_id);
804   if (NULL != hostname) LOG_DEBUG ("-------hostname: %s\n", hostname);
805   if (0 != username_length) LOG_DEBUG ("-------username: %s\n", username);
806   else LOG_DEBUG ("-------username: NULL\n");
807   LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
808   host = GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
809                                              ntohs (msg->ssh_port));
810   GNUNET_SERVER_receive_done (client, GNUNET_OK);
811   reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
812   if (GNUNET_OK != host_list_add (host))
813   {    
814     /* We are unable to add a host */  
815     emsg = "A host exists with given host-id";
816     LOG_DEBUG ("%s: %u", emsg, host_id);
817     GNUNET_TESTBED_host_destroy (host);
818     reply_size += strlen (emsg) + 1;
819     reply = GNUNET_malloc (reply_size);
820     memcpy (&reply[1], emsg, strlen (emsg) + 1);
821   }
822   else
823     reply = GNUNET_malloc (reply_size);  
824   reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
825   reply->header.size = htons (reply_size);
826   reply->host_id = htonl (host_id);  
827   queue_message (client, (struct GNUNET_MessageHeader *) reply);
828 }
829
830
831 /**
832  * Iterator over hash map entries.
833  *
834  * @param cls closure
835  * @param key current key code
836  * @param value value in the hash map
837  * @return GNUNET_YES if we should continue to
838  *         iterate,
839  *         GNUNET_NO if not.
840  */
841 int ss_exists_iterator (void *cls,
842                         const struct GNUNET_HashCode * key,
843                         void *value)
844 {
845   struct SharedService *queried_ss = cls;
846   struct SharedService *ss = value;
847
848   if (0 == strcmp (ss->name, queried_ss->name))
849     return GNUNET_NO;
850   else
851     return GNUNET_YES;
852 }
853
854
855 /**
856  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
857  *
858  * @param cls NULL
859  * @param client identification of the client
860  * @param message the actual message
861  */
862 static void 
863 handle_configure_shared_service (void *cls,
864                                  struct GNUNET_SERVER_Client *client,
865                                  const struct GNUNET_MessageHeader *message)
866 {
867   const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
868   struct SharedService *ss;
869   char *service_name;
870   struct GNUNET_HashCode hash;
871   uint16_t msg_size;
872   uint16_t service_name_size;
873     
874   msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
875   msg_size = ntohs (message->size);
876   if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
877   {
878     GNUNET_break (0);
879     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
880     return;
881   }
882   service_name_size = msg_size - 
883     sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
884   service_name = (char *) &msg[1];
885   if ('\0' != service_name[service_name_size - 1])
886   {
887     GNUNET_break (0);
888     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
889     return;
890   }
891   LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
892              service_name, ntohl (msg->num_peers));
893   if (ntohl (msg->host_id) != master_context->host_id)
894   {
895     route_message (ntohl (msg->host_id), message);
896     GNUNET_SERVER_receive_done (client, GNUNET_OK);
897     return;
898   }
899   GNUNET_SERVER_receive_done (client, GNUNET_OK);
900   ss = GNUNET_malloc (sizeof (struct SharedService));
901   ss->name = strdup (service_name);
902   ss->num_shared = ntohl (msg->num_peers);
903   GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
904   if (GNUNET_SYSERR == 
905       GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
906                                                   &ss_exists_iterator, ss))
907   {
908     LOG (GNUNET_ERROR_TYPE_WARNING,
909          "Service %s already configured as a shared service. "
910          "Ignoring service sharing request \n", ss->name);
911     GNUNET_free (ss->name);
912     GNUNET_free (ss);
913     return;
914   }
915   GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
916                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);  
917 }
918
919
920 /**
921  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
922  *
923  * @param cls NULL
924  * @param client identification of the client
925  * @param message the actual message
926  */
927 static void 
928 handle_link_controllers (void *cls,
929                          struct GNUNET_SERVER_Client *client,
930                          const struct GNUNET_MessageHeader *message)
931 {
932   const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
933   struct GNUNET_CONFIGURATION_Handle *cfg;
934   struct LCFContextQueue *lcfq;
935   struct Route *route;
936   struct Route *new_route;
937   char *config;  
938   uLongf dest_size;
939   size_t config_size;
940   uint32_t delegated_host_id;
941   uint32_t slave_host_id;
942   uint16_t msize;
943    
944   if (NULL == master_context)
945   {
946     GNUNET_break (0);
947     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
948     return;
949   }
950   msize = ntohs (message->size);
951   if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
952   {
953     GNUNET_break (0);
954     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
955     return;
956   }
957   msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
958   delegated_host_id = ntohl (msg->delegated_host_id);
959   if (delegated_host_id == master_context->host_id)
960   {
961     GNUNET_break (0);
962     LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
963     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
964     return;
965   }
966   if ((delegated_host_id >= host_list_size) || 
967       (NULL == host_list[delegated_host_id]))
968   {
969     LOG (GNUNET_ERROR_TYPE_WARNING, "Delegated host not registered with us\n");
970     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
971     return;
972   }
973   slave_host_id = ntohl (msg->slave_host_id);
974   if ((slave_host_id >= host_list_size) || (NULL == host_list[slave_host_id]))
975   {
976     LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host not registered with us\n");
977     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
978     return;
979   }
980   if (slave_host_id == delegated_host_id)
981   {
982     LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
983     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
984     return;
985   }
986   msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
987   config_size = ntohs (msg->config_size);
988   
989   if (slave_host_id == master_context->host_id) /* Link from us */
990   {
991     struct Slave *slave;
992
993     if ((delegated_host_id < slave_list_size) && 
994         (NULL != slave_list[delegated_host_id])) /* We have already added */
995     {
996       LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
997            delegated_host_id);
998       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
999       return;
1000     }    
1001     config = GNUNET_malloc (config_size);
1002     dest_size = (uLongf) config_size;    
1003     if (Z_OK != uncompress ((Bytef *) config, &dest_size,
1004                             (const Bytef *) &msg[1], (uLong) msize))
1005     {
1006       GNUNET_break (0);           /* Compression error */
1007       GNUNET_free (config);
1008       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1009       return;
1010     }
1011     if (config_size == dest_size)
1012     {
1013       LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1014       GNUNET_free (config);
1015       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1016     }
1017     cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1018     if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, config_size,
1019                                                        GNUNET_NO))
1020     {
1021       GNUNET_break (0);           /* Configuration parsing error */
1022       GNUNET_free (config);
1023       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1024       return;
1025     }
1026     GNUNET_free (config);
1027     if ((delegated_host_id < slave_list_size) &&
1028         (NULL != slave_list[delegated_host_id]))
1029     {
1030       GNUNET_break (0);           /* Configuration parsing error */
1031       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1032       return;
1033     }
1034     slave = GNUNET_malloc (sizeof (struct Slave));
1035     slave->host_id = delegated_host_id;
1036     slave_list_add (slave);
1037     if (1 == msg->is_subordinate)
1038     {
1039       slave->controller_proc =
1040         GNUNET_TESTBED_controller_start (test_system,
1041                                          host_list[delegated_host_id],
1042                                          cfg, &slave_shutdown_handler,
1043                                          slave);
1044     }
1045     slave->controller =
1046       GNUNET_TESTBED_controller_connect (cfg, host_list[delegated_host_id],
1047                                          master_context->event_mask,
1048                                          &slave_event_callback, slave);
1049     GNUNET_CONFIGURATION_destroy (cfg);
1050     new_route = GNUNET_malloc (sizeof (struct Route));
1051     new_route->dest = delegated_host_id;
1052     new_route->thru = master_context->host_id;
1053     route_list_add (new_route);
1054     GNUNET_SERVER_receive_done (client, GNUNET_OK);
1055     return;
1056   }
1057
1058   /* Route the request */
1059   if (slave_host_id >= route_list_size)
1060   {
1061     LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1062     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1063     return;
1064   }
1065   while (NULL != (route = route_list[slave_host_id]))
1066   {
1067     if (route->thru == master_context->host_id)
1068       break;
1069     slave_host_id = route->thru;
1070   }
1071   GNUNET_assert (NULL != route); /* because we add routes carefully */
1072   GNUNET_assert (route->dest < slave_list_size);
1073   GNUNET_assert (NULL != slave_list[route->dest]);  
1074   lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1075   lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1076   lcfq->lcf->delegated_host_id = delegated_host_id;
1077   lcfq->lcf->is_subordinate =
1078     (1 == msg->is_subordinate) ? GNUNET_YES : GNUNET_NO;
1079   lcfq->lcf->state = INIT;
1080   lcfq->lcf->gateway = slave_list[route->dest];
1081   lcfq->lcf->sxcfg_size = msize;
1082   lcfq->lcf->sxcfg = GNUNET_malloc (msize);
1083   lcfq->lcf->scfg_size = config_size;
1084   (void) memcpy (lcfq->lcf->sxcfg, &msg[1], msize);
1085   if (NULL == lcfq_head)
1086   {
1087     GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1088     GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1089     lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq);
1090   }
1091   else
1092     GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1093   GNUNET_SERVER_receive_done (client, GNUNET_OK);
1094   new_route = GNUNET_malloc (sizeof (struct Route));
1095   new_route->dest = delegated_host_id;
1096   new_route->thru = route->dest;
1097   route_list_add (new_route);
1098 }
1099
1100
1101 /**
1102  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1103  *
1104  * @param cls NULL
1105  * @param client identification of the client
1106  * @param message the actual message
1107  */
1108 static void 
1109 handle_peer_create (void *cls,
1110                     struct GNUNET_SERVER_Client *client,
1111                     const struct GNUNET_MessageHeader *message)
1112 {
1113   const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1114   struct GNUNET_CONFIGURATION_Handle *cfg;
1115   char *config;
1116   size_t dest_size;
1117   int ret;
1118   uint32_t config_size;
1119   uint16_t msize;
1120   
1121
1122   msize = ntohs (message->size);
1123   if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1124   {
1125     GNUNET_break (0);           /* We need configuration */
1126     GNUNET_SERVER_receive_done (client, GNUNET_OK);
1127     return;
1128   }
1129   msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1130   if (ntohl (msg->host_id) == master_context->host_id)
1131   {
1132     struct Peer *peer;
1133     char *emsg;
1134     
1135     /* We are responsible for this peer */
1136     msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1137     config_size = ntohl (msg->config_size);    
1138     config = GNUNET_malloc (config_size);
1139     dest_size = config_size;
1140     if (Z_OK != (ret = uncompress ((Bytef *) config, (uLongf *) &dest_size,
1141                                    (const Bytef *) &msg[1], (uLong) msize)))
1142     {
1143       GNUNET_break (0);           /* uncompression error */
1144       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1145       return;
1146     }
1147     if (config_size != dest_size)
1148     {
1149       GNUNET_break (0);/* Uncompressed config size mismatch */
1150       GNUNET_free (config);
1151       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1152       return;
1153     }
1154     cfg = GNUNET_CONFIGURATION_create ();
1155     if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, config_size,
1156                                                        GNUNET_NO))
1157     {
1158       GNUNET_break (0);           /* Configuration parsing error */
1159       GNUNET_free (config);
1160       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1161       return;
1162     }
1163     GNUNET_free (config);
1164     peer = GNUNET_malloc (sizeof (struct Peer));
1165     peer->cfg = cfg;
1166     peer->id = ntohl (msg->peer_id);
1167     LOG_DEBUG ("Creating peer with id: %u\n", peer->id);
1168     peer->peer = GNUNET_TESTING_peer_configure (test_system, peer->cfg,
1169                                                 peer->id,
1170                                                 NULL /* Peer id */,
1171                                                 &emsg);
1172     if (NULL == peer->peer)
1173     {
1174       LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1175       GNUNET_free (emsg);
1176       GNUNET_break (0);
1177       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1178       return;
1179     }
1180     peer_list_add (peer);
1181     GNUNET_SERVER_receive_done (client, GNUNET_OK);
1182     return;
1183   }
1184
1185   /* Forward the peer to other host */
1186   GNUNET_break (0);
1187   GNUNET_SERVER_receive_done (client, GNUNET_OK);
1188 }
1189
1190
1191 /**
1192  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1193  *
1194  * @param cls NULL
1195  * @param client identification of the client
1196  * @param message the actual message
1197  */
1198 static void 
1199 handle_peer_destroy (void *cls,
1200                      struct GNUNET_SERVER_Client *client,
1201                      const struct GNUNET_MessageHeader *message)
1202 {
1203   const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1204   struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *reply;
1205   uint32_t peer_id;
1206   uint32_t id;
1207   uint16_t reply_size;
1208   
1209   msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1210   peer_id = ntohl (msg->peer_id);
1211   LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1212              peer_id, GNUNET_ntohll (msg->operation_id));
1213   if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id]))
1214   {
1215     GNUNET_break (0);
1216     /* Reply with failure event message */
1217   }  
1218   GNUNET_TESTING_peer_destroy (peer_list[peer_id]->peer);
1219   GNUNET_CONFIGURATION_destroy (peer_list[peer_id]->cfg);
1220   GNUNET_free (peer_list[peer_id]);
1221   peer_list[peer_id] = NULL;
1222   for (id = 0; id < LIST_GROW_STEP; id++)
1223   {
1224     if (((peer_id + id >= peer_list_size) ||
1225          (NULL != peer_list[peer_id])))
1226       break;
1227   }
1228   if (LIST_GROW_STEP == id)
1229   {
1230     peer_list_size -= LIST_GROW_STEP;
1231     peer_list = GNUNET_realloc (peer_list, peer_list_size);
1232   }
1233   reply_size = 
1234     sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
1235   reply = GNUNET_malloc (reply_size);
1236   reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
1237   reply->header.size = htons (reply_size);
1238   reply->operation_id = msg->operation_id;
1239   queue_message (client, (struct GNUNET_MessageHeader *) reply);
1240   
1241 }
1242
1243
1244 /**
1245  * Iterator over hash map entries.
1246  *
1247  * @param cls closure
1248  * @param key current key code
1249  * @param value value in the hash map
1250  * @return GNUNET_YES if we should continue to
1251  *         iterate,
1252  *         GNUNET_NO if not.
1253  */
1254 static int 
1255 ss_map_free_iterator (void *cls,
1256                       const struct GNUNET_HashCode * key, void *value)
1257 {
1258   struct SharedService *ss = value;
1259
1260   GNUNET_assert (GNUNET_YES ==
1261                  GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
1262   GNUNET_free (ss->name);
1263   GNUNET_free (ss);
1264   return GNUNET_YES;
1265 }
1266
1267
1268 /**
1269  * Task to clean up and shutdown nicely
1270  *
1271  * @param cls NULL
1272  * @param tc the TaskContext from scheduler
1273  */
1274 static void
1275 shutdown_task (void *cls,
1276                const struct GNUNET_SCHEDULER_TaskContext *tc)
1277 {
1278   struct LCFContextQueue *lcfq;
1279   uint32_t id;
1280
1281   shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
1282   GNUNET_SCHEDULER_shutdown ();
1283   LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
1284   (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
1285                                                 NULL);
1286   GNUNET_CONTAINER_multihashmap_destroy (ss_map);
1287   GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
1288   if (NULL != fh)
1289   {
1290     GNUNET_DISK_file_close (fh);
1291     fh = NULL;
1292   }
1293   if (NULL != lcfq_head)
1294   {
1295     if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
1296     {
1297       GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
1298       lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
1299     }
1300     if (NULL != lcfq_head->lcf->rhandle)
1301       GNUNET_TESTBED_cancel_registration (lcfq_head->lcf->rhandle);
1302   }
1303   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1304   for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
1305   {
1306     GNUNET_free (lcfq->lcf->sxcfg);
1307     GNUNET_free (lcfq->lcf);
1308     GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
1309     GNUNET_free (lcfq);
1310   }
1311   /* Clear peer list */
1312   for (id = 0; id < peer_list_size; id++)
1313     if (NULL != peer_list[id])
1314     {
1315       GNUNET_TESTING_peer_destroy (peer_list[id]->peer);
1316       GNUNET_CONFIGURATION_destroy (peer_list[id]->cfg);
1317       GNUNET_free (peer_list[id]);
1318     }
1319   GNUNET_free_non_null (peer_list);
1320   /* Clear host list */
1321   for (id = 0; id < host_list_size; id++)
1322     if (NULL != host_list[id])
1323       GNUNET_TESTBED_host_destroy (host_list[id]);
1324   GNUNET_free_non_null (host_list);
1325   /* Clear route list */
1326   for (id = 0; id < route_list_size; id++)
1327     if (NULL != route_list[id])
1328       GNUNET_free (route_list[id]);
1329   GNUNET_free_non_null (route_list);
1330   /* Clear slave_list */
1331   for (id = 0; id < slave_list_size; id++)
1332     if (NULL != slave_list[id])
1333     {
1334       GNUNET_assert (NULL != slave_list[id]->controller);
1335       GNUNET_TESTBED_controller_disconnect (slave_list[id]->controller);
1336       if (NULL != slave_list[id]->controller_proc)
1337         GNUNET_TESTBED_controller_stop (slave_list[id]->controller_proc);
1338     }
1339   GNUNET_free_non_null (master_context);
1340 }
1341
1342
1343 /**
1344  * Debug shutdown task in case of stdin getting closed
1345  *
1346  * @param cls NULL
1347  * @param tc the TaskContext from scheduler
1348  */
1349 static void
1350 shutdown_task_ (void *cls,
1351                 const struct GNUNET_SCHEDULER_TaskContext *tc)
1352 {
1353   LOG (GNUNET_ERROR_TYPE_DEBUG, "STDIN closed ...\n");
1354   shutdown_task (cls, tc);
1355 }
1356
1357
1358 /**
1359  * Callback for client disconnect
1360  *
1361  * @param cls NULL
1362  * @param client the client which has disconnected
1363  */
1364 static void
1365 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
1366 {
1367   if (NULL == master_context)
1368     return;
1369   if (client == master_context->client)
1370   {
1371     LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
1372     GNUNET_SERVER_client_drop (client);
1373     /* should not be needed as we're terminated by failure to read
1374        from stdin, but if stdin fails for some reason, this shouldn't 
1375        hurt for now --- might need to revise this later if we ever
1376        decide that master connections might be temporarily down 
1377        for some reason */
1378     GNUNET_SCHEDULER_shutdown ();
1379   }
1380 }
1381
1382
1383 /**
1384  * Testbed setup
1385  *
1386  * @param cls closure
1387  * @param server the initialized server
1388  * @param cfg configuration to use
1389  */
1390 static void 
1391 testbed_run (void *cls,
1392              struct GNUNET_SERVER_Handle *server,
1393              const struct GNUNET_CONFIGURATION_Handle *cfg)
1394 {
1395   static const struct GNUNET_SERVER_MessageHandler message_handlers[] =
1396     {
1397       {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT,
1398        sizeof (struct GNUNET_TESTBED_InitMessage)},
1399       {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
1400       {&handle_configure_shared_service, NULL,
1401        GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
1402       {&handle_link_controllers, NULL,
1403        GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
1404       {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
1405       {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER,
1406        sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
1407       {NULL}
1408     };
1409
1410   config = GNUNET_CONFIGURATION_dup (cfg);
1411   GNUNET_SERVER_add_handlers (server,
1412                               message_handlers);
1413   GNUNET_SERVER_disconnect_notify (server,
1414                                    &client_disconnect_cb,
1415                                    NULL);
1416   ss_map = GNUNET_CONTAINER_multihashmap_create (5);
1417   test_system = GNUNET_TESTING_system_create ("testbed", NULL);
1418   
1419   fh = GNUNET_DISK_get_handle_from_native (stdin);
1420   if (NULL == fh)
1421     shutdown_task_id = 
1422       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,                                  
1423                                     &shutdown_task,
1424                                     NULL);
1425   else
1426     shutdown_task_id = 
1427       GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1428                                       fh,
1429                                       &shutdown_task_,
1430                                       NULL);
1431   LOG_DEBUG ("Testbed startup complete\n");
1432 }
1433
1434
1435 /**
1436  * The starting point of execution
1437  */
1438 int main (int argc, char *const *argv)
1439 {
1440   return
1441     (GNUNET_OK ==
1442      GNUNET_SERVICE_run (argc,
1443                          argv,
1444                          "testbed",
1445                          GNUNET_SERVICE_OPTION_NONE,
1446                          &testbed_run,
1447                          NULL)) ? 0 : 1;
1448 }