routing
[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
36 /**
37  * Generic logging
38  */
39 #define LOG(kind,...)                           \
40   GNUNET_log (kind, __VA_ARGS__)
41
42 /**
43  * Debug logging
44  */
45 #define LOG_DEBUG(...)                          \
46   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
47
48 struct Context
49 {
50   /**
51    * The client handle associated with this context
52    */
53   struct GNUNET_SERVER_Client *client;
54   
55   /**
56    * Event mask of event to be responded in this context
57    */
58   uint64_t event_mask;
59
60   /**
61    * Our host id according to this context
62    */
63   uint32_t host_id;
64 };
65
66
67 /**
68  * The message queue for sending messages to clients
69  */
70 struct MessageQueue
71 {
72   /**
73    * The message to be sent
74    */
75   struct GNUNET_MessageHeader *msg;
76
77   /**
78    * The client to send the message to
79    */
80   struct GNUNET_SERVER_Client *client;
81   
82   /**
83    * next pointer for DLL
84    */
85   struct MessageQueue *next;
86   
87   /**
88    * prev pointer for DLL
89    */
90   struct MessageQueue *prev;
91 };
92
93
94 /**
95  * The structure for identifying a shared service
96  */
97 struct SharedService
98 {
99   /**
100    * The name of the shared service
101    */
102   char *name;
103
104   /**
105    * Number of shared peers per instance of the shared service
106    */
107   uint32_t num_shared;
108
109   /**
110    * Number of peers currently sharing the service
111    */
112   uint32_t num_sharing;
113 };
114
115
116 /**
117  * A routing entry
118  */
119 struct Route
120 {
121   /**
122    * The destination host
123    */
124   const struct GNUNET_TESTBED_Host *dest;
125
126   /**
127    * The forwarding (next hop) host
128    */
129   const struct GNUNET_TESTBED_Host *fhost;
130
131   /**
132    * The controller handle if we have started the controller at the next hop
133    * host 
134    */
135   struct GNUNET_TESTBED_Controller *fcontroller;
136 };
137
138
139 /**
140  * Wrapped stdin.
141  */
142 static struct GNUNET_DISK_FileHandle *fh;
143
144 /**
145  * The master context; generated with the first INIT message
146  */
147 static struct Context *master_context;
148
149 /**
150  * The shutdown task handle
151  */
152 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
153
154 /**
155  * Array of host list
156  */
157 static struct GNUNET_TESTBED_Host **host_list;
158
159 /**
160  * The size of the host list
161  */
162 static uint32_t host_list_size;
163
164 /**
165  * A list of routes
166  */
167 static struct Route **route_list;
168
169 /**
170  * The size of the route list
171  */
172 static uint32_t route_list_size;
173
174 /**
175  * The message queue head
176  */
177 static struct MessageQueue *mq_head;
178
179 /**
180  * The message queue tail
181  */
182 static struct MessageQueue *mq_tail;
183
184 /**
185  * Current Transmit Handle; NULL if no notify transmit exists currently
186  */
187 struct GNUNET_SERVER_TransmitHandle *transmit_handle;
188
189 /**
190  * The hashmap of shared services
191  */
192 struct GNUNET_CONTAINER_MultiHashMap *ss_map;
193
194
195 /**
196  * Function called to notify a client about the connection begin ready to queue
197  * more data.  "buf" will be NULL and "size" zero if the connection was closed
198  * for writing in the meantime.
199  *
200  * @param cls NULL
201  * @param size number of bytes available in buf
202  * @param buf where the callee should write the message
203  * @return number of bytes written to buf
204  */
205 static size_t
206 transmit_ready_notify (void *cls, size_t size, void *buf)
207 {
208   struct MessageQueue *mq_entry;
209
210   transmit_handle = NULL;
211   mq_entry = mq_head;
212   GNUNET_assert (NULL != mq_entry);
213   if (0 == size)
214     return 0;
215   GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
216   size = ntohs (mq_entry->msg->size);
217   memcpy (buf, mq_entry->msg, size);
218   GNUNET_free (mq_entry->msg);
219   GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
220   GNUNET_free (mq_entry);
221   mq_entry = mq_head;
222   if (NULL != mq_entry)
223     transmit_handle = 
224       GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
225                                            ntohs (mq_entry->msg->size),
226                                            GNUNET_TIME_UNIT_FOREVER_REL,
227                                            &transmit_ready_notify, NULL);
228   return size;
229 }
230
231
232 /**
233  * Queues a message in send queue for sending to the service
234  *
235  * @param client the client to whom the queued message has to be sent
236  * @param msg the message to queue
237  */
238 static void
239 queue_message (struct GNUNET_SERVER_Client *client,
240                struct GNUNET_MessageHeader *msg)
241 {
242   struct MessageQueue *mq_entry;
243   uint16_t type;
244   uint16_t size;
245
246   type = ntohs (msg->type);
247   size = ntohs (msg->size);
248   GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
249                  (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));                 
250   mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
251   mq_entry->msg = msg;
252   mq_entry->client = client;
253   LOG_DEBUG ( "Queueing message of type %u, size %u for sending\n", type,
254               ntohs (msg->size));
255   GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
256   if (NULL == transmit_handle)
257     transmit_handle = 
258       GNUNET_SERVER_notify_transmit_ready (client, size,
259                                            GNUNET_TIME_UNIT_FOREVER_REL,
260                                            &transmit_ready_notify, NULL);
261 }
262
263
264 /**
265  * Function to add a host to the current list of known hosts
266  *
267  * @param host the host to add 
268  * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
269  *           already in use
270  */
271 static int
272 host_list_add (struct GNUNET_TESTBED_Host *host)
273 {
274   uint32_t host_id;
275   
276   host_id = GNUNET_TESTBED_host_get_id_ (host);
277   if (host_list_size <= host_id)
278   {
279     host_list = GNUNET_realloc (host_list, 
280                                 sizeof (struct GNUNET_TESTBED_Host *)
281                                 * (host_id + 10));
282     host_list_size += (host_id + 10);
283   }
284   if (NULL != host_list[host_id])
285   {
286     LOG_DEBUG ("A host with id: %u already exists\n", host_id);
287     return GNUNET_SYSERR;
288   }
289   host_list[host_id] = host;
290   return GNUNET_OK;
291 }
292
293
294 /**
295  * Routes message to a host given its host_id
296  *
297  * @param host_id the id of the destination host
298  * @param msg the message to be routed
299  */
300 static void
301 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
302 {
303   GNUNET_break (0);
304 }
305
306
307 /**
308  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
309  *
310  * @param cls NULL
311  * @param client identification of the client
312  * @param message the actual message
313  */
314 static void 
315 handle_init (void *cls,
316              struct GNUNET_SERVER_Client *client,
317              const struct GNUNET_MessageHeader *message)
318 {
319   const struct GNUNET_TESTBED_InitMessage *msg;
320   struct GNUNET_TESTBED_Host *host;
321
322   if (NULL != master_context)
323   {
324     GNUNET_break (0);
325     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
326     return;
327   }
328   msg = (const struct GNUNET_TESTBED_InitMessage *) message;  
329   master_context = GNUNET_malloc (sizeof (struct Context));
330   master_context->client = client;
331   master_context->host_id = ntohl (msg->host_id);
332   host = GNUNET_TESTBED_host_create_with_id (master_context->host_id,
333                                              NULL, NULL, 0);
334   host_list_add (host);
335   master_context->event_mask = GNUNET_ntohll (msg->event_mask);
336   GNUNET_SERVER_client_keep (client);
337   LOG_DEBUG ("Created master context with host ID: %u\n",
338              master_context->host_id);
339   GNUNET_SERVER_receive_done (client, GNUNET_OK);
340 }
341
342
343 /**
344  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
345  *
346  * @param cls NULL
347  * @param client identification of the client
348  * @param message the actual message
349  */
350 static void 
351 handle_add_host (void *cls,
352                  struct GNUNET_SERVER_Client *client,
353                  const struct GNUNET_MessageHeader *message)
354 {
355   struct GNUNET_TESTBED_Host *host;
356   const struct GNUNET_TESTBED_AddHostMessage *msg;
357   struct GNUNET_TESTBED_HostConfirmedMessage *reply;
358   char *username;
359   char *hostname;
360   char *emsg;
361   uint32_t host_id;
362   uint16_t username_length;
363   uint16_t hostname_length;
364   uint16_t reply_size;
365   
366   msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
367   username_length = ntohs (msg->user_name_length);
368   username_length = (0 == username_length) ? 0 : username_length + 1;
369   username = (char *) &(msg[1]);
370   hostname = username + username_length;
371   if (ntohs (message->size) <=
372       (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length))
373   {
374     GNUNET_break (0);
375     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
376     return;
377   }
378   hostname_length = ntohs (message->size)
379     - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
380   if (strlen (hostname) != hostname_length)
381   {
382     GNUNET_break (0);
383     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
384     return;
385   }
386   host_id = ntohl (msg->host_id);
387   LOG_DEBUG ("Received ADDHOST message\n");
388   LOG_DEBUG ("-------host id: %u\n", host_id);
389   if (NULL != hostname) LOG_DEBUG ("-------hostname: %s\n", hostname);
390   if (NULL != username) LOG_DEBUG ("-------username: %s\n", username);
391   LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
392   host = GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
393                                              ntohs (msg->ssh_port));
394   GNUNET_SERVER_receive_done (client, GNUNET_OK);
395   reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
396   if (GNUNET_OK != host_list_add (host))
397   {    
398     /* We are unable to add a host */  
399     emsg = "A host exists with given host-id";
400     LOG_DEBUG ("%s: %u", emsg, host_id);
401     GNUNET_TESTBED_host_destroy (host);
402     reply_size += strlen (emsg) + 1;
403     reply = GNUNET_malloc (reply_size);
404     memcpy (&reply[1], emsg, strlen (emsg) + 1);
405   }
406   else
407     reply = GNUNET_malloc (reply_size);  
408   reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
409   reply->header.size = htons (reply_size);
410   reply->host_id = htonl (host_id);  
411   queue_message (client, (struct GNUNET_MessageHeader *) reply);
412 }
413
414
415 /**
416  * Iterator over hash map entries.
417  *
418  * @param cls closure
419  * @param key current key code
420  * @param value value in the hash map
421  * @return GNUNET_YES if we should continue to
422  *         iterate,
423  *         GNUNET_NO if not.
424  */
425 int ss_exists_iterator (void *cls,
426                         const struct GNUNET_HashCode * key,
427                         void *value)
428 {
429   struct SharedService *queried_ss = cls;
430   struct SharedService *ss = value;
431
432   if (0 == strcmp (ss->name, queried_ss->name))
433     return GNUNET_NO;
434   else
435     return GNUNET_YES;
436 }
437
438 /**
439  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
440  *
441  * @param cls NULL
442  * @param client identification of the client
443  * @param message the actual message
444  */
445 static void 
446 handle_configure_shared_service (void *cls,
447                                  struct GNUNET_SERVER_Client *client,
448                                  const struct GNUNET_MessageHeader *message)
449 {
450   const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
451   struct SharedService *ss;
452   char *service_name;
453   struct GNUNET_HashCode hash;
454   uint16_t msg_size;
455   uint16_t service_name_size;
456     
457   msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
458   msg_size = ntohs (message->size);
459   if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
460   {
461     GNUNET_break (0);
462     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
463     return;
464   }
465   service_name_size = msg_size - 
466     sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
467   service_name = (char *) &msg[1];
468   if ('\0' != service_name[service_name_size - 1])
469   {
470     GNUNET_break (0);
471     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
472     return;
473   }
474   LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
475              service_name, ntohl (msg->num_peers));
476   if (ntohl (msg->host_id) != master_context->host_id)
477   {
478     route_message (ntohl (msg->host_id), message);
479     GNUNET_SERVER_receive_done (client, GNUNET_OK);
480     return;
481   }
482   GNUNET_SERVER_receive_done (client, GNUNET_OK);
483   ss = GNUNET_malloc (sizeof (struct SharedService));
484   ss->name = strdup (service_name);
485   ss->num_shared = ntohl (msg->num_peers);
486   GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
487   if (GNUNET_SYSERR == 
488       GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
489                                                   &ss_exists_iterator, ss))
490   {
491     LOG (GNUNET_ERROR_TYPE_WARNING,
492          "Service %s already configured as a shared service. "
493          "Ignoring service sharing request \n", ss->name);
494     GNUNET_free (ss->name);
495     GNUNET_free (ss);
496     return;
497   }
498   GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
499                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);  
500 }
501
502
503 /**
504  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
505  *
506  * @param cls NULL
507  * @param client identification of the client
508  * @param message the actual message
509  */
510 static void 
511 handle_link_controllers (void *cls,
512                          struct GNUNET_SERVER_Client *client,
513                          const struct GNUNET_MessageHeader *message)
514 {
515   const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
516   struct GNUNET_CONFIGURATION_Handle *cfg;
517   char *config;  
518   uLongf dest_size;
519   size_t config_size;
520   uint32_t delegated_host_id;
521   uint32_t slave_host_id;
522   uint16_t msize;
523    
524   msize = ntohs (message->size);
525   if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
526   {
527     GNUNET_break (0);
528     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
529     return;
530   }
531   msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
532   delegated_host_id = ntohl (msg->delegated_host_id);
533   if (delegated_host_id == master_context->host_id)
534   {
535     GNUNET_break (0);
536     LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
537     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
538     return;
539   }
540   if ((delegated_host_id < route_list_size) &&
541       (NULL != route_list[delegated_host_id]))
542   {
543     LOG (GNUNET_ERROR_TYPE_WARNING,
544          "Delegated host has already been linked\n");
545     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
546     return;
547   }
548   if ((delegated_host_id >= host_list_size) || 
549       (NULL == host_list[delegated_host_id]))
550   {
551     LOG (GNUNET_ERROR_TYPE_WARNING, "Delegated host not registered with us\n");
552     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
553     return;
554   }
555   slave_host_id = ntohl (msg->slave_host_id);
556   if ((slave_host_id >= host_list_size) || (NULL == host_list[slave_host_id]))
557   {
558     LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host not registered with us\n");
559     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
560     return;
561   }
562   config_size = ntohs (msg->config_size);
563   config = GNUNET_malloc (config_size);
564   dest_size = (uLongf) config_size;
565   msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
566   if (Z_OK != uncompress ((Bytef *) config, &dest_size,
567                           (const Bytef *) &msg[1], (uLong) msize))
568   {
569     GNUNET_break (0);           /* Compression error */
570     GNUNET_free (config);
571     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
572     return;
573   }
574   GNUNET_assert (config_size == dest_size);
575   cfg = GNUNET_CONFIGURATION_create ();
576   if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, config_size,
577                                                      GNUNET_NO))
578   {
579     GNUNET_break (0);           /* Configuration parsing error */
580     GNUNET_break (config);
581     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
582     return;
583   }
584   GNUNET_free (config);
585   GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
586   /* If we are not the slave controller then we have to route the request
587      towards the slave controller */
588   if (1 == msg->is_subordinate)
589   {
590     GNUNET_break (0);           /* FIXME: Implement the slave controller
591                                    startup */ 
592   }  
593   GNUNET_CONFIGURATION_destroy (cfg);
594 }
595
596
597 /**
598  * Iterator over hash map entries.
599  *
600  * @param cls closure
601  * @param key current key code
602  * @param value value in the hash map
603  * @return GNUNET_YES if we should continue to
604  *         iterate,
605  *         GNUNET_NO if not.
606  */
607 static int 
608 ss_map_free_iterator (void *cls,
609                       const struct GNUNET_HashCode * key, void *value)
610 {
611   struct SharedService *ss = value;
612
613   GNUNET_assert (GNUNET_YES ==
614                  GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
615   GNUNET_free (ss->name);
616   GNUNET_free (ss);
617   return GNUNET_YES;
618 }
619
620
621 /**
622  * Task to clean up and shutdown nicely
623  *
624  * @param cls NULL
625  * @param tc the TaskContext from scheduler
626  */
627 static void
628 shutdown_task (void *cls,
629                const struct GNUNET_SCHEDULER_TaskContext *tc)
630 {
631   uint32_t host_id;
632   uint32_t route_id;
633
634   shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
635   GNUNET_SCHEDULER_shutdown ();
636   LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
637   (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
638                                                 NULL);
639   GNUNET_CONTAINER_multihashmap_destroy (ss_map);
640   if (NULL != fh)
641   {
642     GNUNET_DISK_file_close (fh);
643     fh = NULL;
644   }
645   /* Clear host list */
646   for (host_id = 0; host_id < host_list_size; host_id++)
647     if (NULL != host_list[host_id])
648       GNUNET_TESTBED_host_destroy (host_list[host_id]);
649   GNUNET_free_non_null (host_list);
650   /* Clear route list */
651   for (route_id = 0; route_id < route_list_size; route_id++)
652     if (NULL != route_list[route_id])
653     {
654       if (NULL != route_list[route_id]->fcontroller)
655         GNUNET_TESTBED_controller_stop (route_list[route_id]->fcontroller);
656       GNUNET_free (route_list[route_id]);
657     }
658   GNUNET_free_non_null (route_list);
659   GNUNET_free_non_null (master_context);
660 }
661
662
663 /**
664  * Callback for client disconnect
665  *
666  * @param cls NULL
667  * @param client the client which has disconnected
668  */
669 static void
670 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
671 {
672   if (NULL == master_context)
673     return;
674   if (client == master_context->client)
675   {
676     LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
677     GNUNET_SERVER_client_drop (client);
678     /* should not be needed as we're terminated by failure to read
679        from stdin, but if stdin fails for some reason, this shouldn't 
680        hurt for now --- might need to revise this later if we ever
681        decide that master connections might be temporarily down 
682        for some reason */
683     GNUNET_SCHEDULER_shutdown ();
684   }
685 }
686
687
688 /**
689  * Testbed setup
690  *
691  * @param cls closure
692  * @param server the initialized server
693  * @param cfg configuration to use
694  */
695 static void 
696 testbed_run (void *cls,
697              struct GNUNET_SERVER_Handle *server,
698              const struct GNUNET_CONFIGURATION_Handle *cfg)
699 {
700   static const struct GNUNET_SERVER_MessageHandler message_handlers[] =
701     {
702       {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT,
703        sizeof (struct GNUNET_TESTBED_InitMessage)},
704       {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
705       {&handle_configure_shared_service, NULL,
706        GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
707       {&handle_link_controllers, NULL,
708        GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
709       {NULL}
710     };
711
712   GNUNET_SERVER_add_handlers (server,
713                               message_handlers);
714   GNUNET_SERVER_disconnect_notify (server,
715                                    &client_disconnect_cb,
716                                    NULL);
717   ss_map = GNUNET_CONTAINER_multihashmap_create (5);
718   fh = GNUNET_DISK_get_handle_from_native (stdin);
719   if (NULL == fh)
720     shutdown_task_id = 
721       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,                                  
722                                     &shutdown_task,
723                                     NULL);
724   else
725     shutdown_task_id = 
726       GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
727                                       fh,
728                                       &shutdown_task,
729                                       NULL);
730 }
731
732
733 /**
734  * The starting point of execution
735  */
736 int main (int argc, char *const *argv)
737 {
738   return
739     (GNUNET_OK ==
740      GNUNET_SERVICE_run (argc,
741                          argv,
742                          "testbed",
743                          GNUNET_SERVICE_OPTION_NONE,
744                          &testbed_run,
745                          NULL)) ? 0 : 1;
746 }