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