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