towards handling suboperations during overlay connect
[oweals/gnunet.git] / src / testbed / test_testbed_api_3peers_3controllers.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/test_testbed_api_3peers_3controllers.c
23  * @brief testcases for the testbed api: 3 peers are configured, started and
24  *          connected together. Each peer resides on its own controller.
25  * @author Sree Harsha Totakura
26  */
27
28
29 /**
30  * The testing architecture is:
31  *                  A
32  *                 / \
33  *                /   \
34  *               B === C 
35  * A is the master controller and B, C are slave controllers. B links to C
36  * laterally.
37  * Peers are mapped to controllers in the following relations:
38  *             Peer         Controller
39  *               1              A
40  *               2              B
41  *               3              C
42  *
43  */
44
45 #include "platform.h"
46 #include "gnunet_util_lib.h"
47 #include "gnunet_testing_lib-new.h"
48 #include "gnunet_testbed_service.h"
49
50
51 /**
52  * Generic logging shortcut
53  */
54 #define LOG(kind,...)                           \
55   GNUNET_log (kind, __VA_ARGS__)
56
57 /**
58  * Relative time seconds shorthand
59  */
60 #define TIME_REL_SECS(sec) \
61   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
62
63
64 /**
65  * Peer context
66  */
67 struct PeerContext
68 {
69   /**
70    * The peer handle
71    */
72   struct GNUNET_TESTBED_Peer *peer;
73
74   /**
75    * Operations involving this peer
76    */
77   struct GNUNET_TESTBED_Operation *operation;
78
79   /**
80    * set to GNUNET_YES when peer is started
81    */
82   int is_running;
83 };
84
85 /**
86  * Our localhost
87  */
88 static struct GNUNET_TESTBED_Host *host;
89
90 /**
91  * The controller process of one controller
92  */
93 static struct GNUNET_TESTBED_ControllerProc *cp1;
94
95 /**
96  * A neighbouring host
97  */
98 static struct GNUNET_TESTBED_Host *neighbour1;
99
100 /**
101  * Another neighbouring host
102  */
103 static struct GNUNET_TESTBED_Host *neighbour2;
104
105 /**
106  * Handle for neighbour registration
107  */
108 static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
109
110 /**
111  * The controller handle of one controller
112  */
113 static struct GNUNET_TESTBED_Controller *controller1;
114
115 /**
116  * peer 1
117  */
118 static struct PeerContext peer1;
119
120 /**
121  * peer2
122  */
123 static struct PeerContext peer2;
124
125 /**
126  * peer3
127  */
128 static struct PeerContext peer3;
129
130 /**
131  * Handle to starting configuration
132  */
133 static struct GNUNET_CONFIGURATION_Handle *cfg;
134
135 /**
136  * Handle to slave controller C's configuration, used to establish lateral link from
137  * master controller
138  */
139 static struct GNUNET_CONFIGURATION_Handle *cfg2;
140
141 /**
142  * Handle to operations involving both peers
143  */
144 static struct GNUNET_TESTBED_Operation *common_operation;
145
146 /**
147  * Abort task identifier
148  */
149 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
150
151 /**
152  * Delayed connect job identifier
153  */
154 static GNUNET_SCHEDULER_TaskIdentifier delayed_connect_task;
155
156 /**
157  * Different stages in testing
158  */
159 enum Stage
160 {
161
162   /**
163    * Initial stage
164    */
165   INIT,
166
167   /**
168    * Controller 1 has started
169    */
170   CONTROLLER1_UP,
171
172   /**
173    * peer1 is created
174    */
175   PEER1_CREATED,
176
177   /**
178    * peer1 is started
179    */
180   PEER1_STARTED,
181
182   /**
183    * Controller 2 has started
184    */
185   CONTROLLER2_UP,
186
187   /**
188    * peer2 is created
189    */
190   PEER2_CREATED,
191
192   /**
193    * peer2 is started
194    */
195   PEER2_STARTED,
196
197   /**
198    * Controller 3 has started
199    */
200   CONTROLLER3_UP,
201
202   /**
203    * Peer3 is created
204    */
205   PEER3_CREATED,
206
207   /**
208    * Peer3 started
209    */
210   PEER3_STARTED,
211
212   /**
213    * peer1 and peer2 are connected
214    */
215   PEERS_1_2_CONNECTED,
216
217   /**
218    * Configuration of C has been acquired
219    */
220   CONTROLLER_CFG_ACQUIRED,
221
222   /**
223    * Linking controller B to C laterally
224    */
225   CONTROLLERS_LATERALLY_LINKED,
226
227   /**
228    * peer2 and peer3 are connected
229    */
230   PEERS_2_3_CONNECTED,
231
232   /**
233    * Peers are connected once again (this should not fail as they are already connected)
234    */
235   PEERS_CONNECTED_2,
236
237   /**
238    * peers are stopped
239    */
240   PEERS_STOPPED,
241
242   /**
243    * Final success stage
244    */
245   SUCCESS
246 };
247
248 /**
249  * The testing result
250  */
251 static enum Stage result;
252
253 /**
254  * Shutdown nicely
255  *
256  * @param cls NULL
257  * @param tc the task context
258  */
259 static void
260 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
261 {
262   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
263     GNUNET_SCHEDULER_cancel (abort_task);
264   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task);
265   if (NULL != reg_handle)
266     GNUNET_TESTBED_cancel_registration (reg_handle);
267   if (NULL != controller1)
268     GNUNET_TESTBED_controller_disconnect (controller1);
269   GNUNET_CONFIGURATION_destroy (cfg);
270   if (NULL != cfg2)
271     GNUNET_CONFIGURATION_destroy (cfg2);
272   if (NULL != cp1)
273     GNUNET_TESTBED_controller_stop (cp1);
274   if (NULL != host)
275     GNUNET_TESTBED_host_destroy (host);
276   if (NULL != neighbour1)
277     GNUNET_TESTBED_host_destroy (neighbour1);
278   if (NULL != neighbour2)
279     GNUNET_TESTBED_host_destroy (neighbour2);
280 }
281
282
283 /**
284  * abort task to run on test timed out
285  *
286  * @param cls NULL
287  * @param tc the task context
288  */
289 static void
290 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
291 {
292   LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
293   abort_task = GNUNET_SCHEDULER_NO_TASK;
294   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task);
295   do_shutdown (cls, tc);
296 }
297
298
299 /**
300  * Callback to be called when an operation is completed
301  *
302  * @param cls the callback closure from functions generating an operation
303  * @param op the operation that has been finished
304  * @param emsg error message in case the operation has failed; will be NULL if
305  *          operation has executed successfully.
306  */
307 static void 
308 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
309
310
311 /**
312  * task for delaying a connect
313  *
314  * @param cls NULL
315  * @param tc the task context
316  */
317 static void
318 do_delayed_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
319 {
320   delayed_connect_task = GNUNET_SCHEDULER_NO_TASK;
321   GNUNET_assert (NULL == common_operation);
322   common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, 
323                                                      peer1.peer, peer2.peer);
324 }
325
326
327 /**
328  * Callback to be called when an operation is completed
329  *
330  * @param cls the callback closure from functions generating an operation
331  * @param op the operation that has been finished
332  * @param emsg error message in case the operation has failed; will be NULL if
333  *          operation has executed successfully.
334  */
335 static void 
336 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
337 {
338   GNUNET_assert (common_operation == op);
339   switch(result)
340   {
341   case PEER3_STARTED:
342     GNUNET_assert (NULL == peer1.operation);
343     GNUNET_assert (NULL == peer2.operation);
344     GNUNET_assert (NULL != common_operation);
345     GNUNET_TESTBED_operation_done (common_operation);
346     common_operation = NULL;
347     result = PEERS_1_2_CONNECTED;
348     LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
349     common_operation = 
350         GNUNET_TESTBED_get_slave_config (NULL, controller1, neighbour2);
351     break;
352   case PEERS_2_3_CONNECTED:
353     GNUNET_assert (NULL == peer1.operation);
354     GNUNET_assert (NULL == peer2.operation);
355     GNUNET_assert (NULL != common_operation);
356     GNUNET_TESTBED_operation_done (common_operation);
357     common_operation = NULL;
358     result = PEERS_CONNECTED_2;
359     LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
360     peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer, NULL, NULL);
361     peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer, NULL, NULL);
362     peer3.operation = GNUNET_TESTBED_peer_stop (peer3.peer, NULL, NULL);
363     break;
364   case CONTROLLERS_LATERALLY_LINKED:
365     GNUNET_TESTBED_operation_done (common_operation);
366     common_operation = NULL;
367     result = PEERS_2_3_CONNECTED;
368     delayed_connect_task =
369         GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3),
370                                       &do_delayed_connect, NULL);
371     break;
372   default:
373     GNUNET_assert (0);
374   }
375 }
376
377
378 /**
379  * Functions of this signature are called when a peer has been successfully
380  * created
381  *
382  * @param cls NULL
383  * @param peer the handle for the created peer; NULL on any error during
384  *          creation
385  * @param emsg NULL if peer is not NULL; else MAY contain the error description
386  */
387 static void
388 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
389 {
390   switch (result)
391   {
392   case CONTROLLER1_UP:
393     GNUNET_assert (NULL != peer1.operation);
394     GNUNET_assert (NULL != peer);
395     GNUNET_assert (NULL == peer1.peer);
396     peer1.peer = peer;
397     GNUNET_TESTBED_operation_done (peer1.operation);
398     result = PEER1_CREATED;
399     peer1.operation = GNUNET_TESTBED_peer_start (peer, NULL, NULL);
400     break;
401   case CONTROLLER2_UP:
402     GNUNET_assert (NULL != peer2.operation);
403     GNUNET_assert (NULL != peer);
404     GNUNET_assert (NULL == peer2.peer);
405     peer2.peer = peer;
406     GNUNET_TESTBED_operation_done (peer2.operation);
407     result = PEER2_CREATED;
408     peer2.operation = GNUNET_TESTBED_peer_start (peer, NULL, NULL);
409     break;
410   case CONTROLLER3_UP:
411     GNUNET_assert (NULL != peer3.operation);
412     GNUNET_assert (NULL != peer);
413     GNUNET_assert (NULL == peer3.peer);
414     peer3.peer = peer;
415     GNUNET_TESTBED_operation_done (peer3.operation);
416     result = PEER3_CREATED;
417     peer3.operation = GNUNET_TESTBED_peer_start (peer, NULL, NULL);
418     break;
419   default:
420     GNUNET_assert (0);
421   }  
422 }
423
424
425 /**
426  * Callback to signal successfull startup of the controller process
427  *
428  * @param cls the closure from GNUNET_TESTBED_controller_start()
429  * @param cfg the configuration with which the controller has been started;
430  *          NULL if status is not GNUNET_OK
431  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
432  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
433  */
434 static void
435 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status);
436
437
438 /**
439  * Signature of the event handler function called by the
440  * respective event controller.
441  *
442  * @param cls closure
443  * @param event information about the event
444  */
445 static void
446 controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
447 {
448   switch (event->type)
449   {
450   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
451     GNUNET_assert (NULL == event->details.operation_finished.op_cls);
452     GNUNET_assert (NULL == event->details.operation_finished.emsg);
453     switch (result)
454     {      
455     case PEERS_STOPPED:
456       GNUNET_assert (NULL == event->details.operation_finished.generic);
457       if (event->details.operation_finished.operation == peer1.operation)
458       {
459         GNUNET_TESTBED_operation_done (peer1.operation);
460         peer1.operation = NULL;
461         peer1.peer = NULL;
462       }
463       else if (event->details.operation_finished.operation == peer2.operation)
464       {
465         GNUNET_TESTBED_operation_done (peer2.operation);
466         peer2.operation = NULL;
467         peer2.peer = NULL;
468       }
469       else if (event->details.operation_finished.operation == peer3.operation)
470       {
471         GNUNET_TESTBED_operation_done (peer3.operation);
472         peer3.operation = NULL;
473         peer3.peer = NULL;
474       }
475       else
476         GNUNET_assert (0);
477       if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
478       {
479         result = SUCCESS;
480         GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
481       }
482       break;
483     case PEER1_STARTED:
484       GNUNET_assert (NULL == event->details.operation_finished.generic);
485       GNUNET_assert (NULL != common_operation);
486       GNUNET_TESTBED_operation_done (common_operation);
487       common_operation = NULL;
488       result = CONTROLLER2_UP;
489       peer2.operation =
490           GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg,
491                                       &peer_create_cb, NULL);
492       GNUNET_assert (NULL != peer2.operation);
493       break;
494     case PEER2_STARTED:
495       GNUNET_assert (NULL == event->details.operation_finished.generic);
496       GNUNET_assert (NULL != common_operation);
497       GNUNET_TESTBED_operation_done (common_operation);
498       common_operation = NULL;
499       result = CONTROLLER3_UP;
500       peer3.operation =
501           GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg,
502                                       &peer_create_cb, NULL);
503       GNUNET_assert (NULL != peer3.operation);
504       break;
505     case PEERS_1_2_CONNECTED:
506       GNUNET_assert (NULL != event->details.operation_finished.generic);
507       cfg2 = 
508           GNUNET_CONFIGURATION_dup (event->details.operation_finished.generic);
509       GNUNET_TESTBED_operation_done (common_operation);
510       result = CONTROLLER_CFG_ACQUIRED;
511       common_operation =
512           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, neighbour1,
513                                           cfg2, GNUNET_NO);
514       break;
515     case CONTROLLER_CFG_ACQUIRED:
516       GNUNET_assert (NULL == event->details.operation_finished.generic);
517       GNUNET_TESTBED_operation_done (common_operation);
518       result = CONTROLLERS_LATERALLY_LINKED;
519       common_operation =
520           GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
521                                           peer3.peer);      
522       break;
523     default:
524       GNUNET_assert (0);
525     }
526     break;
527   case GNUNET_TESTBED_ET_PEER_START:    
528     switch (result)
529     {
530     case PEER1_CREATED:
531       GNUNET_assert (event->details.peer_start.host == host);
532       peer1.is_running = GNUNET_YES;
533       GNUNET_TESTBED_operation_done (peer1.operation);
534       peer1.operation = NULL;
535       result = PEER1_STARTED;
536       common_operation =
537           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL, cfg,
538                                           GNUNET_YES); 
539       break;
540     case PEER2_CREATED:
541       GNUNET_assert (event->details.peer_start.host == neighbour1);
542       peer2.is_running = GNUNET_YES;
543       GNUNET_TESTBED_operation_done (peer2.operation);
544       peer2.operation = NULL;
545       result = PEER2_STARTED;
546       GNUNET_assert (NULL == common_operation);              
547       common_operation =
548           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL, cfg,
549                                           GNUNET_YES);
550       GNUNET_assert (NULL != common_operation);
551       break;
552     case PEER3_CREATED:
553       GNUNET_assert (event->details.peer_start.host == neighbour2);
554       peer3.is_running = GNUNET_YES;
555       GNUNET_TESTBED_operation_done (peer3.operation);
556       peer3.operation = NULL;
557       result = PEER3_STARTED;
558       common_operation =
559           GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
560                                           peer2.peer);
561       break;
562     default:
563       GNUNET_assert (0);
564     }    
565     break;
566   case GNUNET_TESTBED_ET_PEER_STOP:
567     GNUNET_assert (PEERS_CONNECTED_2 == result);
568     if (event->details.peer_stop.peer == peer1.peer)
569     {
570       peer1.is_running = GNUNET_NO;
571       GNUNET_TESTBED_operation_done (peer1.operation);
572     }
573     else if (event->details.peer_stop.peer == peer2.peer)
574     {
575       peer2.is_running = GNUNET_NO;
576       GNUNET_TESTBED_operation_done (peer2.operation);
577     }
578     else if (event->details.peer_stop.peer == peer3.peer)
579     {
580       peer3.is_running = GNUNET_NO;
581       GNUNET_TESTBED_operation_done (peer3.operation);
582     }
583     else
584       GNUNET_assert (0);
585     if ((GNUNET_NO == peer1.is_running) &&
586         (GNUNET_NO == peer2.is_running) &&
587         (GNUNET_NO == peer3.is_running))
588     {
589       result = PEERS_STOPPED;
590       peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
591       peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
592       peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer);
593     }
594     break;
595   case GNUNET_TESTBED_ET_CONNECT:
596     GNUNET_assert (NULL == peer1.operation);
597     GNUNET_assert (NULL == peer2.operation);
598     GNUNET_assert (NULL == peer3.operation);
599     switch (result)
600     {
601     case PEER3_STARTED:
602       GNUNET_assert (NULL != common_operation);
603       GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) &&
604                      (event->details.peer_connect.peer2 == peer2.peer));
605       break;
606     case PEERS_2_3_CONNECTED:
607       GNUNET_assert (NULL != common_operation);
608       GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) &&
609                      (event->details.peer_connect.peer2 == peer2.peer));
610       break;
611     case CONTROLLERS_LATERALLY_LINKED:
612       GNUNET_assert (NULL != common_operation);
613       GNUNET_assert ((event->details.peer_connect.peer1 == peer2.peer) &&
614                      (event->details.peer_connect.peer2 == peer3.peer));
615       break;
616     default:
617       GNUNET_assert (0);
618     }
619     break;
620   default:
621     GNUNET_assert (0);
622   };
623 }
624
625
626 /**
627  * Callback which will be called to after a host registration succeeded or failed
628  *
629  * @param cls the host which has been registered
630  * @param emsg the error message; NULL if host registration is successful
631  */
632 static void
633 registration_comp (void *cls, const char *emsg)
634 {
635   reg_handle = NULL;
636   if (cls == neighbour1)
637   {
638     neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
639     GNUNET_assert (NULL != neighbour2);
640     reg_handle =
641         GNUNET_TESTBED_register_host (controller1, neighbour2, &registration_comp,
642                                       neighbour2);
643     GNUNET_assert (NULL != reg_handle);
644     return;
645   }
646   GNUNET_assert (cls == neighbour2);
647   peer1.operation =
648       GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb,
649                                   &peer1);
650   GNUNET_assert (NULL != peer1.operation);  
651 }
652
653
654 /**
655  * Callback to signal successfull startup of the controller process
656  *
657  * @param cls the closure from GNUNET_TESTBED_controller_start()
658  * @param cfg the configuration with which the controller has been started;
659  *          NULL if status is not GNUNET_OK
660  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
661  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
662  */
663 static void
664 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
665 {
666   uint64_t event_mask;
667   
668   GNUNET_assert (GNUNET_OK == status);
669   event_mask = 0;
670   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
671   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
672   event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
673   event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
674   switch (result)
675   {
676   case INIT:
677     controller1 =
678         GNUNET_TESTBED_controller_connect (config, host, event_mask, &controller_cb,
679                                            NULL);
680     GNUNET_assert (NULL != controller1);
681     result = CONTROLLER1_UP;
682     neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
683     GNUNET_assert (NULL != neighbour1);
684     reg_handle =
685         GNUNET_TESTBED_register_host (controller1, neighbour1, &registration_comp,
686                                       neighbour1);
687     GNUNET_assert (NULL != reg_handle);
688     break;
689   default:
690     GNUNET_assert (0);
691   }  
692 }
693
694
695 /**
696  * Main run function.
697  *
698  * @param cls NULL
699  * @param args arguments passed to GNUNET_PROGRAM_run
700  * @param cfgfile the path to configuration file
701  * @param cfg the configuration file handle
702  */
703 static void
704 run (void *cls, char *const *args, const char *cfgfile,
705      const struct GNUNET_CONFIGURATION_Handle *config)
706 {
707   host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
708   GNUNET_assert (NULL != host);
709   cfg = GNUNET_CONFIGURATION_dup (config);
710   cp1 = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb,
711                                          NULL);
712   abort_task =
713       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
714                                     (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
715                                     NULL);
716 }
717
718
719 /**
720  * Function to check if 
721  * 1. Password-less SSH logins to given ip work
722  * 2. gnunet-helper-testbed is found on the PATH on the remote side
723  *
724  * @param host_str numeric representation of the host's ip
725  * @return GNUNET_YES if password-less SSH login to the given host works;
726  *           GNUNET_NO if not
727  */
728 static int
729 check_ssh (char *host_str)
730 {
731   char *const remote_args[] = {
732     "ssh", "-o", "BatchMode=yes", "-o", "CheckHostIP=no", 
733     "-o", "NoHostAuthenticationForLocalhost=yes", "-q",
734     host_str, "which", "gnunet-helper-testbed", NULL
735   };
736   struct GNUNET_OS_Process *auxp;
737   enum GNUNET_OS_ProcessStatusType type;
738   unsigned long code;
739   int ret;
740
741   auxp =
742       GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL,
743                                    NULL, "ssh", remote_args);
744   GNUNET_assert (NULL != auxp);
745   do
746   {
747     ret = GNUNET_OS_process_status (auxp, &type, &code);
748     GNUNET_assert (GNUNET_SYSERR != ret);
749     (void) usleep (300);
750   }
751   while (GNUNET_NO == ret);
752   (void) GNUNET_OS_process_wait (auxp);
753   GNUNET_OS_process_destroy (auxp);
754   return (0 != code) ? GNUNET_NO : GNUNET_YES;
755 }
756
757
758 /**
759  * Main function
760  */
761 int
762 main (int argc, char **argv)
763 {
764   char *const argv2[] = { "test_testbed_api_3peers_3controllers",
765                           "-c", "test_testbed_api.conf",
766                           NULL
767   };
768   struct GNUNET_GETOPT_CommandLineOption options[] = {
769     GNUNET_GETOPT_OPTION_END
770   };
771   int ret;
772
773   if (GNUNET_YES != check_ssh ("127.0.0.1"))
774     goto error_exit;
775   result = INIT;
776   ret =
777       GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
778                           "test_testbed_api_3peers_3controllers", "nohelp",
779                           options, &run, NULL);
780   if ((GNUNET_OK != ret) || (SUCCESS != result))
781     return 1;
782   return 0;
783
784  error_exit:
785   (void) PRINTF ("%s",
786                  "Unable to run the test as this system is not configured "
787                  "to use password less SSH logins to localhost.\n"
788                  "Marking test as successful\n");
789   return 0;
790 }
791
792 /* end of test_testbed_api_3peers_3controllers.c */