1a176c129929b233abc49266bde5fd24808b5d86
[oweals/gnunet.git] / src / transport / test_transport_testing.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, 30)
50
51 static struct PeerContext * p;
52
53 static void
54 notify_connect (void *cls,
55                 const struct GNUNET_PeerIdentity *peer,
56                 const struct GNUNET_TRANSPORT_ATS_Information *ats,
57                 uint32_t ats_count)
58 {
59   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
60        GNUNET_i2s (peer));
61 }
62
63 static void
64 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
65 {
66   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n",
67        GNUNET_i2s (peer));
68 }
69
70 static void
71 notify_receive (void *cls,
72                 const struct GNUNET_PeerIdentity *peer,
73                 const struct GNUNET_MessageHeader *message,
74                 const struct GNUNET_TRANSPORT_ATS_Information *ats,
75                 uint32_t ats_count)
76 {
77   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
78 }
79
80
81 static void
82 run (void *cls,
83      char *const *args,
84      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
85 {
86   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
87   p = GNUNET_TRANSPORT_TESTING_start_peer("test_quota_compliance_tcp_peer1.conf");
88
89   if (p != NULL)
90     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer was successfully started\n");
91   else
92     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer was not started successfully\n");
93   GNUNET_assert (p != NULL);
94
95
96   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tConnecting to transport service\n");
97   GNUNET_assert (p->th == NULL);
98   p->th = GNUNET_TRANSPORT_connect(p->cfg, NULL,
99                             NULL,
100                             &notify_receive,
101                             &notify_connect,
102                             &notify_disconnect);
103   GNUNET_assert (p->th != NULL);
104
105   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tDisconnecting to transport service\n");
106   GNUNET_TRANSPORT_disconnect(p->th);
107
108   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n");
109   GNUNET_TRANSPORT_TESTING_stop_peer(p);
110
111   GNUNET_free (p);
112 }
113
114 int
115 main (int argc, char *argv[])
116 {
117   int ret = 0;
118
119   GNUNET_log_setup ("test_transport_testing",
120 #if VERBOSE
121                     "DEBUG",
122 #else
123                     "WARNING",
124 #endif
125                     NULL);
126
127   char *const argv_1[] = { "test_transport_testing",
128     "-c",
129     "test_transport_api_data.conf",
130 #if VERBOSE
131     "-L", "DEBUG",
132 #endif
133     NULL
134   };
135
136   struct GNUNET_GETOPT_CommandLineOption options[] = {
137     GNUNET_GETOPT_OPTION_END
138   };
139
140   GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1,
141                       argv_1, "test_transport_testing", "nohelp",
142                       options, &run, &ret);
143
144   return ret;
145 }
146
147 /* end of test_transport_api.c */