966f66fff2f027aa2aa264915b39e6c367286237
[oweals/gnunet.git] / src / transport / test_transport_api.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010 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  * @file transport/test_transport_api.c
22  * @brief base test case for transport implementations
23  *
24  * This test case serves as a base for tcp, udp, and udp-nat
25  * transport test cases.  Based on the executable being run
26  * the correct test case will be performed.  Conservation of
27  * C code apparently.
28  */
29 #include "platform.h"
30 #include "gnunet_common.h"
31 #include "gnunet_hello_lib.h"
32 #include "gnunet_getopt_lib.h"
33 #include "gnunet_os_lib.h"
34 #include "gnunet_program_lib.h"
35 #include "gnunet_scheduler_lib.h"
36 #include "gnunet_transport_service.h"
37 #include "transport.h"
38 #include "transport-testing.h"
39
40 #define VERBOSE GNUNET_NO
41
42 #define VERBOSE_ARM GNUNET_NO
43
44 #define START_ARM GNUNET_YES
45
46 /**
47  * How long until we give up on transmitting the message?
48  */
49 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
50
51 /**
52  * How long until we give up on transmitting the message?
53  */
54 #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
55
56 #define MTYPE 12345
57
58 static struct PeerContext p1;
59
60 static struct PeerContext p2;
61
62 static int ok;
63
64 static int is_tcp;
65
66 static int is_tcp_nat;
67
68 static int is_udp;
69
70 static int is_unix;
71
72 static int is_udp_nat;
73
74 static int is_http;
75
76 static int is_https;
77
78 static int is_multi_protocol;
79
80 static int is_wlan;
81
82 static  GNUNET_SCHEDULER_TaskIdentifier die_task;
83
84 static  GNUNET_SCHEDULER_TaskIdentifier tct;
85
86 static char * key_file_p1;
87 static char * cert_file_p1;
88
89 static char * key_file_p2;
90 static char * cert_file_p2;
91
92 struct GNUNET_TRANSPORT_TransmitHandle * th;
93
94 #if VERBOSE
95 #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
96 #else
97 #define OKPP do { ok++; } while (0)
98 #endif
99
100
101 static void
102 end ()
103 {
104   GNUNET_assert (ok == 6);
105   GNUNET_SCHEDULER_cancel (die_task);
106   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
107               "Disconnecting from transports!\n");
108   if (th != NULL)
109     GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
110   th = NULL;
111
112   GNUNET_TRANSPORT_disconnect (p1.th);
113   GNUNET_TRANSPORT_disconnect (p2.th);
114   die_task = GNUNET_SCHEDULER_NO_TASK;
115   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
116               "Transports disconnected, returning success!\n");
117   ok = 0;
118 }
119
120 static void
121 stop_arm (struct PeerContext *p)
122 {
123 #if START_ARM
124   if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
125     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
126   GNUNET_OS_process_wait (p->arm_proc);
127   GNUNET_OS_process_close (p->arm_proc);
128   p->arm_proc = NULL;
129 #endif
130   GNUNET_CONFIGURATION_destroy (p->cfg);
131 }
132
133
134 static void
135 end_badly ()
136 {
137   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
138   GNUNET_break (0);
139
140   if (th != NULL)
141     GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
142   th = NULL;
143
144   GNUNET_TRANSPORT_disconnect (p1.th);
145   GNUNET_TRANSPORT_disconnect (p2.th);
146   if (GNUNET_SCHEDULER_NO_TASK != tct)
147     {
148       GNUNET_SCHEDULER_cancel (tct);
149       tct = GNUNET_SCHEDULER_NO_TASK;
150     }
151   ok = 1;
152 }
153
154
155 static void
156 notify_receive (void *cls,
157                 const struct GNUNET_PeerIdentity *peer,
158                 const struct GNUNET_MessageHeader *message,
159                 const struct GNUNET_TRANSPORT_ATS_Information *ats,
160                 uint32_t ats_count)
161 {
162   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
163               "Received message of type %d from peer %s!\n",
164               ntohs(message->type), 
165               GNUNET_i2s (peer));
166   GNUNET_assert (ok == 5);
167   OKPP;
168   GNUNET_assert (MTYPE == ntohs (message->type));
169   GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
170                  ntohs (message->size));
171   end ();
172 }
173
174
175 static size_t
176 notify_ready (void *cls, size_t size, void *buf)
177 {
178   struct PeerContext *p = cls;
179   struct GNUNET_MessageHeader *hdr;
180
181   th = NULL;
182
183   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
184               "Transmitting message with %u bytes to peer %s\n", 
185               sizeof (struct GNUNET_MessageHeader),
186               GNUNET_i2s (&p->id));
187   GNUNET_assert (size >= 256);
188   GNUNET_assert (ok == 4);
189   OKPP;
190   if (buf != NULL)
191   {
192     hdr = buf;
193     hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
194     hdr->type = htons (MTYPE);
195   }
196   return sizeof (struct GNUNET_MessageHeader);
197 }
198
199
200 static void
201 exchange_hello_last (void *cls,
202                      const struct GNUNET_MessageHeader *message)
203 {
204   struct PeerContext *me = cls;
205
206   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207               "Exchanging HELLO of size %d with peer (%s)!\n", 
208               (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
209               GNUNET_i2s (&me->id));
210   GNUNET_assert (message != NULL);
211   GNUNET_assert (GNUNET_OK ==
212                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
213                                       message, &me->id));
214   GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
215 }
216
217
218
219 static void
220 exchange_hello (void *cls,
221                 const struct GNUNET_MessageHeader *message)
222 {
223   struct PeerContext *me = cls;
224
225   GNUNET_assert (message != NULL);
226   GNUNET_assert (GNUNET_OK ==
227                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
228                                       message, &me->id));
229   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230               "Exchanging HELLO of size %d from peer %s!\n", 
231               (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
232               GNUNET_i2s (&me->id));
233   GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
234 }
235
236
237
238 static void
239 notify_connect (void *cls,
240                 const struct GNUNET_PeerIdentity *peer,
241                 const struct GNUNET_TRANSPORT_ATS_Information *ats,
242                 uint32_t ats_count)
243 {
244   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245               "Peer `%4s' connected to us (%p)!\n", 
246               GNUNET_i2s (peer), 
247               cls);
248   if (cls == &p1)
249     {
250       GNUNET_assert (ok >= 2);
251       OKPP;
252       OKPP;
253       GNUNET_SCHEDULER_cancel (die_task);
254       GNUNET_SCHEDULER_cancel (tct);
255       tct = GNUNET_SCHEDULER_NO_TASK;
256       GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
257       GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
258       die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
259                                                &end_badly, NULL);
260       th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
261                                               &p2.id,
262                                               256, 0, TIMEOUT, &notify_ready,
263                                               &p1);
264     }
265 }
266
267
268 static void
269 notify_disconnect (void *cls,
270                    const struct GNUNET_PeerIdentity *peer)
271 {
272   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273               "Peer `%4s' disconnected (%p)!\n",
274               GNUNET_i2s (peer), cls);
275 }
276
277
278 static void
279 setup_peer (struct PeerContext *p, 
280             const char *cfgname)
281 {
282   p->cfg = GNUNET_CONFIGURATION_create ();
283
284   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
285   if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
286       GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
287   GNUNET_DISK_directory_remove (p->servicehome);
288
289 #if START_ARM
290   p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
291                                         "gnunet-service-arm",
292 #if VERBOSE_ARM
293                                         "-L", "DEBUG",
294 #endif
295                                         "-c", cfgname, NULL);
296 #endif
297
298
299   if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
300       GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
301
302   if (is_https)
303     {
304       struct stat sbuf;
305       if (p==&p1)
306         {
307           if (GNUNET_CONFIGURATION_have_value (p->cfg,
308                                                "transport-https", "KEY_FILE"))
309             GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1);
310           if (key_file_p1==NULL)
311             GNUNET_asprintf(&key_file_p1,"https.key");
312           if (0 == stat (key_file_p1, &sbuf ))
313             {
314               if (0 == remove(key_file_p1))
315                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
316                             "Successfully removed existing private key file `%s'\n",key_file_p1);
317               else
318                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
319                             "Failed to remove private key file `%s'\n",key_file_p1);
320             }
321           if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
322             GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1);
323           if (cert_file_p1==NULL)
324             GNUNET_asprintf(&cert_file_p1,"https.cert");
325           if (0 == stat (cert_file_p1, &sbuf ))
326             {
327               if (0 == remove(cert_file_p1))
328                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
329                             "Successfully removed existing certificate file `%s'\n",
330                             cert_file_p1);
331               else
332                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
333                             "Failed to remove existing certificate file `%s'\n",
334                             cert_file_p1);
335             }
336         }
337       else if (p==&p2)
338         {
339           if (GNUNET_CONFIGURATION_have_value (p->cfg,
340                                                "transport-https", "KEY_FILE"))
341             GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2);
342           if (key_file_p2==NULL)
343             GNUNET_asprintf(&key_file_p2,"https.key");
344           if (0 == stat (key_file_p2, &sbuf ))
345             {
346               if (0 == remove(key_file_p2))
347                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
348                             "Successfully removed existing private key file `%s'\n",
349                             key_file_p2);
350               else
351                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
352                             "Failed to remove private key file `%s'\n",
353                             key_file_p2);
354             }
355           if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
356             GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2);
357           if (cert_file_p2==NULL)
358             GNUNET_asprintf(&cert_file_p2,"https.cert");
359           if (0 == stat (cert_file_p2, &sbuf ))
360             {
361               if (0 == remove(cert_file_p2))
362                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
363                             "Successfully removed existing certificate file `%s'\n",cert_file_p2);
364               else
365                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
366                             "Failed to remove existing certificate file `%s'\n",cert_file_p2);
367             }
368         }
369     }
370   
371   p->th = GNUNET_TRANSPORT_connect (p->cfg,
372                                     NULL, p,
373                                     &notify_receive,
374                                     &notify_connect, &notify_disconnect);
375   GNUNET_assert (p->th != NULL);
376 }
377
378
379 static void
380 try_connect (void *cls,
381              const struct GNUNET_SCHEDULER_TaskContext *tc)
382 {
383   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
384               "Asking peers to connect...\n");
385   GNUNET_TRANSPORT_try_connect (p2.th,
386                                 &p1.id);
387   GNUNET_TRANSPORT_try_connect (p1.th,
388                                 &p2.id);
389   tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
390                                       &try_connect,
391                                       NULL);
392 }
393
394
395 static void
396 run (void *cls,
397      char *const *args,
398      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
399 {
400   GNUNET_assert (ok == 1);
401   OKPP;
402   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
403                                            &end_badly, NULL);
404
405   if (is_udp)
406     {
407       setup_peer (&p1, "test_transport_api_udp_peer1.conf");
408       setup_peer (&p2, "test_transport_api_udp_peer2.conf");
409     }
410   if (is_unix)
411     {
412       setup_peer (&p1, "test_transport_api_unix_peer1.conf");
413       setup_peer (&p2, "test_transport_api_unix_peer2.conf");
414     }
415   if (is_multi_protocol)
416     {
417       setup_peer (&p1, "test_transport_api_multi_peer1.conf");
418       setup_peer (&p2, "test_transport_api_multi_peer2.conf");
419     }
420   else if (is_tcp)
421     {
422       setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
423       setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
424     }
425   else if (is_tcp_nat)
426     {
427       setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf");
428       setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf");
429     }
430   else if (is_udp_nat)
431     {
432       setup_peer (&p1, "test_transport_api_udp_nat_peer1.conf");
433       setup_peer (&p2, "test_transport_api_udp_nat_peer2.conf");
434     }
435   else if (is_http)
436     {
437       setup_peer (&p1, "test_transport_api_http_peer1.conf");
438       setup_peer (&p2, "test_transport_api_http_peer2.conf");
439     }
440   else if (is_https)
441     {
442       setup_peer (&p1, "test_transport_api_https_peer1.conf");
443       setup_peer (&p2, "test_transport_api_https_peer2.conf");
444     }
445   else if (is_wlan)
446     {
447       setup_peer (&p1, "test_transport_api_wlan_peer1.conf");
448       setup_peer (&p2, "test_transport_api_wlan_peer2.conf");
449     }
450   GNUNET_assert(p1.th != NULL);
451   GNUNET_assert(p2.th != NULL);
452
453   GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
454   GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
455   tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
456 }
457
458 static int
459 check ()
460 {
461   static char *const argv[] = { "test-transport-api",
462     "-c",
463     "test_transport_api_data.conf",
464 #if VERBOSE
465     "-L", "DEBUG",
466 #endif
467     NULL
468   };
469   static struct GNUNET_GETOPT_CommandLineOption options[] = {
470     GNUNET_GETOPT_OPTION_END
471   };
472
473 #if WRITECONFIG
474   setTransportOptions("test_transport_api_data.conf");
475 #endif
476   ok = 1;
477   GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
478                       argv, "test-transport-api", "nohelp",
479                       options, &run, &ok);
480   stop_arm (&p1);
481   stop_arm (&p2);
482
483   if (is_https)
484     {
485       struct stat sbuf;
486       if (0 == stat (cert_file_p1, &sbuf ))
487         {
488           if (0 == remove(cert_file_p1))
489             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
490                         "Successfully removed existing certificate file `%s'\n",cert_file_p1);
491           else
492             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
493                         "Failed to remove certfile `%s'\n",cert_file_p1);
494         }
495       
496       if (0 == stat (key_file_p1, &sbuf ))
497         {
498           if (0 == remove(key_file_p1))
499             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
500                         "Successfully removed private key file `%s'\n",key_file_p1);
501           else
502             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
503                         "Failed to private key file `%s'\n",key_file_p1);
504         }
505       
506       if (0 == stat (cert_file_p2, &sbuf ))
507         {
508           if (0 == remove(cert_file_p2))
509             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510                         "Successfully removed existing certificate file `%s'\n",cert_file_p2);
511           else
512             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
513                         "Failed to remove certfile `%s'\n",cert_file_p2);
514         }
515       
516       if (0 == stat (key_file_p2, &sbuf ))
517         {
518           if (0 == remove(key_file_p2))
519             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
520                         "Successfully removed private key file `%s'\n",key_file_p2);
521           else
522             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
523                         "Failed to private key file `%s'\n",key_file_p2);
524         }
525       GNUNET_free(key_file_p1);
526       GNUNET_free(key_file_p2);
527       GNUNET_free(cert_file_p1);
528       GNUNET_free(cert_file_p2);
529     }
530
531   if ((p1.servicehome != NULL) && (p2.servicehome != NULL))
532   {
533     GNUNET_DISK_directory_remove (p1.servicehome);
534     GNUNET_DISK_directory_remove (p2.servicehome);
535     GNUNET_free(p1.servicehome);
536     GNUNET_free(p2.servicehome);
537   }
538   return ok;
539 }
540
541 /**
542  * Return the actual path to a file found in the current
543  * PATH environment variable.
544  *
545  * @param binary the name of the file to find
546  */
547 static char *
548 get_path_from_PATH (char *binary)
549 {
550   char *path;
551   char *pos;
552   char *end;
553   char *buf;
554   const char *p;
555
556   p = getenv ("PATH");
557   if (p == NULL)
558     {
559       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
560                   _("PATH environment variable is unset.\n"));
561       return NULL;
562     }
563   path = GNUNET_strdup (p);     /* because we write on it */
564   buf = GNUNET_malloc (strlen (path) + 20);
565   pos = path;
566
567   while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
568     {
569       *end = '\0';
570       sprintf (buf, "%s/%s", pos, binary);
571       if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
572         {
573           GNUNET_free (path);
574           return buf;
575         }
576       pos = end + 1;
577     }
578   sprintf (buf, "%s/%s", pos, binary);
579   if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
580     {
581       GNUNET_free (path);
582       return buf;
583     }
584   GNUNET_free (buf);
585   GNUNET_free (path);
586   return NULL;
587 }
588
589 /**
590  * Check whether the suid bit is set on a file.
591  * Attempts to find the file using the current
592  * PATH environment variable as a search path.
593  *
594  * @param binary the name of the file to check
595  *
596  * @return GNUNET_YES if the binary is found and
597  *         can be run properly, GNUNET_NO otherwise
598  */
599 static int
600 check_gnunet_nat_binary(char *binary)
601 {
602   struct stat statbuf;
603   char *p;
604 #ifdef MINGW
605   SOCKET rawsock;
606 #endif
607
608 #ifdef MINGW
609   char *binaryexe;
610   GNUNET_asprintf (&binaryexe, "%s.exe", binary);
611   p = get_path_from_PATH (binaryexe);
612   free (binaryexe);
613 #else
614   p = get_path_from_PATH (binary);
615 #endif
616   if (p == NULL)
617     {
618       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
619                   _("Could not find binary `%s' in PATH!\n"),
620                   binary);
621       return GNUNET_NO;
622     }
623   if (0 != STAT (p, &statbuf))
624     {
625       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
626                   _("stat (%s) failed: %s\n"),
627                   p,
628                   STRERROR (errno));
629       GNUNET_free (p);
630       return GNUNET_SYSERR;
631     }
632   GNUNET_free (p);
633 #ifndef MINGW
634   if ( (0 != (statbuf.st_mode & S_ISUID)) &&
635        (statbuf.st_uid == 0) )
636     return GNUNET_YES;
637   return GNUNET_NO;
638 #else
639   rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
640   if (INVALID_SOCKET == rawsock)
641     {
642       DWORD err = GetLastError ();
643       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
644                   "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err);
645       return GNUNET_NO; /* not running as administrator */
646     }
647   closesocket (rawsock);
648   return GNUNET_YES;
649 #endif
650 }
651
652 int
653 main (int argc, char *argv[])
654 {
655   int ret;
656 #ifdef MINGW
657   return GNUNET_SYSERR;
658 #endif
659
660   GNUNET_log_setup ("test-transport-api",
661 #if VERBOSE
662                     "DEBUG",
663 #else
664                     "WARNING",
665 #endif
666                     NULL);
667
668   if (strstr(argv[0], "tcp_nat") != NULL)
669     {
670       is_tcp_nat = GNUNET_YES;
671       if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
672         {
673           GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
674                       "`%s' not properly installed, cannot run NAT test!\n",
675                       "gnunet-nat-server");
676           return 0;
677         }
678     }
679   else if (strstr(argv[0], "tcp") != NULL)
680     {
681       is_tcp = GNUNET_YES;
682     }
683   else if (strstr(argv[0], "udp_nat") != NULL)
684     {
685       is_udp_nat = GNUNET_YES;
686       if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
687         {
688           GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
689                       "`%s' not properly installed, cannot run NAT test!\n",
690                       "gnunet-nat-server");
691           return 0;
692         }
693     }
694   else if (strstr(argv[0], "udp") != NULL)
695     {
696       is_udp = GNUNET_YES;
697     }
698   else if (strstr(argv[0], "unix") != NULL)
699     {
700       is_unix = GNUNET_YES;
701     }
702   else if (strstr(argv[0], "https") != NULL)
703     {
704       is_https = GNUNET_YES;
705     }
706   else if (strstr(argv[0], "http") != NULL)
707     {
708       is_http = GNUNET_YES;
709     }
710   else if (strstr(argv[0], "wlan") != NULL)
711     {
712        is_wlan = GNUNET_YES;
713     }
714   else if (strstr(argv[0], "multi") != NULL)
715     {
716        is_multi_protocol = GNUNET_YES;
717     }
718
719   ret = check ();
720
721   return ret;
722 }
723
724 /* end of test_transport_api.c */