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