diff options
Diffstat (limited to 'src/transport/test_transport_testing_startstop.c')
-rw-r--r-- | src/transport/test_transport_testing_startstop.c | 106 |
1 files changed, 23 insertions, 83 deletions
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c index 2d035ca70..e1c370627 100644 --- a/src/transport/test_transport_testing_startstop.c +++ b/src/transport/test_transport_testing_startstop.c | |||
@@ -25,21 +25,9 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_common.h" | 27 | #include "gnunet_common.h" |
28 | #include "gnunet_hello_lib.h" | ||
29 | #include "gnunet_getopt_lib.h" | ||
30 | #include "gnunet_os_lib.h" | ||
31 | #include "gnunet_program_lib.h" | ||
32 | #include "gnunet_scheduler_lib.h" | ||
33 | #include "gnunet_transport_service.h" | 28 | #include "gnunet_transport_service.h" |
34 | #include "transport.h" | ||
35 | #include "transport-testing.h" | 29 | #include "transport-testing.h" |
36 | 30 | ||
37 | #define VERBOSE GNUNET_NO | ||
38 | |||
39 | #define VERBOSE_ARM GNUNET_NO | ||
40 | |||
41 | #define START_ARM GNUNET_YES | ||
42 | |||
43 | /** | 31 | /** |
44 | * How long until we give up on transmitting the message? | 32 | * How long until we give up on transmitting the message? |
45 | */ | 33 | */ |
@@ -49,8 +37,6 @@ GNUNET_SCHEDULER_TaskIdentifier timeout_task; | |||
49 | 37 | ||
50 | static struct PeerContext *p; | 38 | static struct PeerContext *p; |
51 | 39 | ||
52 | //static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
53 | |||
54 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | 40 | struct GNUNET_TRANSPORT_TESTING_handle *tth; |
55 | 41 | ||
56 | static int ret = 0; | 42 | static int ret = 0; |
@@ -63,8 +49,7 @@ end () | |||
63 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | 49 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) |
64 | GNUNET_SCHEDULER_cancel (timeout_task); | 50 | GNUNET_SCHEDULER_cancel (timeout_task); |
65 | 51 | ||
66 | if (NULL != p) | 52 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); |
67 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
68 | GNUNET_TRANSPORT_TESTING_done (tth); | 53 | GNUNET_TRANSPORT_TESTING_done (tth); |
69 | } | 54 | } |
70 | 55 | ||
@@ -74,109 +59,64 @@ end_badly () | |||
74 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 59 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 60 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
76 | 61 | ||
77 | if (p != NULL) | 62 | if (NULL != p) |
78 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | 63 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); |
79 | 64 | ||
80 | GNUNET_TRANSPORT_TESTING_done (tth); | 65 | if (NULL != tth) |
66 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
81 | 67 | ||
82 | ret = GNUNET_SYSERR; | 68 | ret = GNUNET_SYSERR; |
83 | } | 69 | } |
84 | 70 | ||
85 | #if 0 | ||
86 | static void | ||
87 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | ||
88 | { | ||
89 | char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
90 | |||
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
92 | "Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps, | ||
93 | p2->no, GNUNET_i2s (&p2->id)); | ||
94 | GNUNET_free (ps); | ||
95 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
96 | } | ||
97 | |||
98 | |||
99 | static void | ||
100 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
101 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", | ||
104 | GNUNET_i2s (peer)); | ||
105 | connected++; | ||
106 | } | ||
107 | 71 | ||
108 | static void | 72 | static void |
109 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
110 | { | ||
111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n", | ||
112 | GNUNET_i2s (peer)); | ||
113 | } | ||
114 | |||
115 | static void | ||
116 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
117 | const struct GNUNET_MessageHeader *message, | ||
118 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | ||
119 | { | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); | ||
121 | } | ||
122 | |||
123 | |||
124 | |||
125 | void | ||
126 | start_cb (struct PeerContext *p, void *cls) | 73 | start_cb (struct PeerContext *p, void *cls) |
127 | { | 74 | { |
128 | static int started; | 75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n", |
129 | 76 | p->no, | |
130 | started++; | ||
131 | |||
132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
133 | GNUNET_i2s (&p->id)); | 77 | GNUNET_i2s (&p->id)); |
134 | 78 | ||
135 | if (started != 2) | 79 | ret = 0; |
136 | return; | 80 | GNUNET_SCHEDULER_add_now (&end, NULL); |
137 | |||
138 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
139 | |||
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
141 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
142 | p->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | ||
143 | GNUNET_free (sender_c); | ||
144 | |||
145 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p, p2, &testing_connect_cb, | ||
146 | NULL); | ||
147 | } | 81 | } |
148 | #endif | 82 | |
149 | 83 | ||
150 | static void | 84 | static void |
151 | run (void *cls, char *const *args, const char *cfgfile, | 85 | run (void *cls, char *const *args, const char *cfgfile, |
152 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 86 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
153 | { | 87 | { |
88 | ret = 1; | ||
154 | tth = GNUNET_TRANSPORT_TESTING_init (); | 89 | tth = GNUNET_TRANSPORT_TESTING_init (); |
155 | GNUNET_assert (NULL != tth); | 90 | GNUNET_assert (NULL != tth); |
156 | 91 | ||
157 | timeout_task = | 92 | timeout_task = |
158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); | 93 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); |
159 | 94 | ||
160 | GNUNET_SCHEDULER_add_now (&end, NULL); | 95 | p = GNUNET_TRANSPORT_TESTING_start_peer(tth, cfgfile, 1, |
96 | NULL, /* receive cb */ | ||
97 | NULL, /* connect cb */ | ||
98 | NULL, /* disconnect cb */ | ||
99 | start_cb, /* startup cb */ | ||
100 | NULL); /* closure */ | ||
101 | if (NULL == p) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); | ||
104 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
105 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
106 | timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
107 | } | ||
161 | } | 108 | } |
162 | 109 | ||
163 | int | 110 | int |
164 | main (int argc, char *argv[]) | 111 | main (int argc, char *argv[]) |
165 | { | 112 | { |
166 | GNUNET_log_setup ("test_transport_testing_startstop", | 113 | GNUNET_log_setup ("test_transport_testing_startstop", |
167 | #if VERBOSE | ||
168 | "DEBUG", | ||
169 | #else | ||
170 | "WARNING", | 114 | "WARNING", |
171 | #endif | ||
172 | NULL); | 115 | NULL); |
173 | 116 | ||
174 | char *const argv_1[] = { "test_transport_testing", | 117 | char *const argv_1[] = { "test_transport_testing", |
175 | "-c", | 118 | "-c", |
176 | "test_transport_api_data.conf", | 119 | "test_transport_api_data.conf", |
177 | #if VERBOSE | ||
178 | "-L", "DEBUG", | ||
179 | #endif | ||
180 | NULL | 120 | NULL |
181 | }; | 121 | }; |
182 | 122 | ||