cb wrapper for connecting peers
[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       &notify_receive,
89       &notify_connect,
90       &notify_disconnect,
91       NULL);
92
93   if (p != NULL)
94     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer was successfully started\n");
95   else
96     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer was not started successfully\n");
97   GNUNET_assert (p != NULL);
98   GNUNET_assert (p->th != NULL);
99
100   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n");
101
102   GNUNET_TRANSPORT_TESTING_stop_peer(p);
103
104
105 }
106
107 int
108 main (int argc, char *argv[])
109 {
110   int ret = 0;
111
112   GNUNET_log_setup ("test_transport_testing",
113 #if VERBOSE
114                     "DEBUG",
115 #else
116                     "WARNING",
117 #endif
118                     NULL);
119
120   char *const argv_1[] = { "test_transport_testing",
121     "-c",
122     "test_transport_api_data.conf",
123 #if VERBOSE
124     "-L", "DEBUG",
125 #endif
126     NULL
127   };
128
129   struct GNUNET_GETOPT_CommandLineOption options[] = {
130     GNUNET_GETOPT_OPTION_END
131   };
132
133   GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1,
134                       argv_1, "test_transport_testing", "nohelp",
135                       options, &run, &ret);
136
137   return ret;
138 }
139
140 /* end of test_transport_api.c */