diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/transport/test_transport_blacklisting.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/test_transport_blacklisting.c')
-rw-r--r-- | src/transport/test_transport_blacklisting.c | 705 |
1 files changed, 352 insertions, 353 deletions
diff --git a/src/transport/test_transport_blacklisting.c b/src/transport/test_transport_blacklisting.c index 0ecd6fda1..1d8ef3fde 100644 --- a/src/transport/test_transport_blacklisting.c +++ b/src/transport/test_transport_blacklisting.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file transport/transport_api_blacklisting.c | 22 | * @file transport/transport_api_blacklisting.c |
@@ -65,9 +65,9 @@ struct GNUNET_TRANSPORT_TESTING_Handle *tth; | |||
65 | /** | 65 | /** |
66 | * How long until we give up on transmitting the message? | 66 | * How long until we give up on transmitting the message? |
67 | */ | 67 | */ |
68 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) | 68 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) |
69 | 69 | ||
70 | #define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 70 | #define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) |
71 | 71 | ||
72 | static int stage; | 72 | static int stage; |
73 | static int ok; | 73 | static int ok; |
@@ -80,7 +80,7 @@ static struct GNUNET_SCHEDULER_Task * timeout_task; | |||
80 | static struct GNUNET_SCHEDULER_Task * stage_task; | 80 | static struct GNUNET_SCHEDULER_Task * stage_task; |
81 | 81 | ||
82 | #if VERBOSE | 82 | #if VERBOSE |
83 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 83 | #define OKPP do { ok++; fprintf(stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
84 | #else | 84 | #else |
85 | #define OKPP do { ok++; } while (0) | 85 | #define OKPP do { ok++; } while (0) |
86 | #endif | 86 | #endif |
@@ -91,99 +91,99 @@ run_stage(void *cls); | |||
91 | 91 | ||
92 | 92 | ||
93 | static void | 93 | static void |
94 | end (void *cls) | 94 | end(void *cls) |
95 | { | 95 | { |
96 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); | 96 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); |
97 | 97 | ||
98 | if (die_task != NULL ) | 98 | if (die_task != NULL) |
99 | { | 99 | { |
100 | GNUNET_SCHEDULER_cancel (die_task); | 100 | GNUNET_SCHEDULER_cancel(die_task); |
101 | die_task = NULL; | 101 | die_task = NULL; |
102 | } | 102 | } |
103 | 103 | ||
104 | if (timeout_task != NULL ) | 104 | if (timeout_task != NULL) |
105 | { | 105 | { |
106 | GNUNET_SCHEDULER_cancel (timeout_task); | 106 | GNUNET_SCHEDULER_cancel(timeout_task); |
107 | timeout_task = NULL; | 107 | timeout_task = NULL; |
108 | } | 108 | } |
109 | 109 | ||
110 | if (stage_task != NULL ) | 110 | if (stage_task != NULL) |
111 | { | 111 | { |
112 | GNUNET_SCHEDULER_cancel (stage_task); | 112 | GNUNET_SCHEDULER_cancel(stage_task); |
113 | stage_task = NULL; | 113 | stage_task = NULL; |
114 | } | 114 | } |
115 | 115 | ||
116 | if (cc != NULL ) | 116 | if (cc != NULL) |
117 | { | 117 | { |
118 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | 118 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); |
119 | cc = NULL; | 119 | cc = NULL; |
120 | } | 120 | } |
121 | 121 | ||
122 | if (p1 != NULL ) | 122 | if (p1 != NULL) |
123 | { | 123 | { |
124 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | 124 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); |
125 | p1 = NULL; | 125 | p1 = NULL; |
126 | } | 126 | } |
127 | if (p2 != NULL ) | 127 | if (p2 != NULL) |
128 | { | 128 | { |
129 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | 129 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); |
130 | p2 = NULL; | 130 | p2 = NULL; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | static void | 135 | static void |
136 | end_badly (void *cls) | 136 | end_badly(void *cls) |
137 | { | 137 | { |
138 | die_task = NULL; | 138 | die_task = NULL; |
139 | 139 | ||
140 | if (timeout_task != NULL ) | 140 | if (timeout_task != NULL) |
141 | { | 141 | { |
142 | GNUNET_SCHEDULER_cancel (timeout_task); | 142 | GNUNET_SCHEDULER_cancel(timeout_task); |
143 | timeout_task = NULL; | 143 | timeout_task = NULL; |
144 | } | 144 | } |
145 | 145 | ||
146 | if (stage_task != NULL ) | 146 | if (stage_task != NULL) |
147 | { | 147 | { |
148 | GNUNET_SCHEDULER_cancel (stage_task); | 148 | GNUNET_SCHEDULER_cancel(stage_task); |
149 | stage_task = NULL; | 149 | stage_task = NULL; |
150 | } | 150 | } |
151 | 151 | ||
152 | if (cc != NULL ) | 152 | if (cc != NULL) |
153 | { | 153 | { |
154 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | 154 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); |
155 | cc = NULL; | 155 | cc = NULL; |
156 | } | 156 | } |
157 | if (p1 != NULL ) | 157 | if (p1 != NULL) |
158 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | 158 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); |
159 | if (p2 != NULL ) | 159 | if (p2 != NULL) |
160 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | 160 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); |
161 | 161 | ||
162 | ok = GNUNET_SYSERR; | 162 | ok = GNUNET_SYSERR; |
163 | } | 163 | } |
164 | 164 | ||
165 | static void | 165 | static void |
166 | testing_connect_cb (void *cls) | 166 | testing_connect_cb(void *cls) |
167 | { | 167 | { |
168 | cc = NULL; | 168 | cc = NULL; |
169 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 169 | char *p1_c = GNUNET_strdup(GNUNET_i2s(&p1->id)); |
170 | 170 | ||
171 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n", | 171 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n", |
172 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | 172 | p1->no, p1_c, p2->no, GNUNET_i2s(&p2->id)); |
173 | GNUNET_free(p1_c); | 173 | GNUNET_free(p1_c); |
174 | connected = GNUNET_YES; | 174 | connected = GNUNET_YES; |
175 | stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL ); | 175 | stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL); |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | static void | 179 | static void |
180 | connect_timeout (void *cls) | 180 | connect_timeout(void *cls) |
181 | { | 181 | { |
182 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 182 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
183 | "Peers not connected, next stage\n"); | 183 | "Peers not connected, next stage\n"); |
184 | timeout_task = NULL; | 184 | timeout_task = NULL; |
185 | stage_task = GNUNET_SCHEDULER_add_now (&run_stage, | 185 | stage_task = GNUNET_SCHEDULER_add_now(&run_stage, |
186 | NULL); | 186 | NULL); |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
@@ -191,340 +191,339 @@ static int started; | |||
191 | 191 | ||
192 | 192 | ||
193 | static void | 193 | static void |
194 | start_cb (void *cls) | 194 | start_cb(void *cls) |
195 | { | 195 | { |
196 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 196 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
197 | |||
197 | started++; | 198 | started++; |
198 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 199 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
199 | "Peer %u (`%s') started\n", | 200 | "Peer %u (`%s') started\n", |
200 | p->no, | 201 | p->no, |
201 | GNUNET_i2s_full (&p->id)); | 202 | GNUNET_i2s_full(&p->id)); |
202 | 203 | ||
203 | if (started != 2) | 204 | if (started != 2) |
204 | return; | 205 | return; |
205 | 206 | ||
206 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 207 | char *sender_c = GNUNET_strdup(GNUNET_i2s(&p1->id)); |
207 | 208 | ||
208 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 209 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
209 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 210 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", |
210 | p1->no, | 211 | p1->no, |
211 | sender_c, | 212 | sender_c, |
212 | p2->no, | 213 | p2->no, |
213 | GNUNET_i2s (&p2->id)); | 214 | GNUNET_i2s(&p2->id)); |
214 | GNUNET_free(sender_c); | 215 | GNUNET_free(sender_c); |
215 | 216 | ||
216 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, | 217 | cc = GNUNET_TRANSPORT_TESTING_connect_peers(p1, |
217 | p2, | 218 | p2, |
218 | &testing_connect_cb, | 219 | &testing_connect_cb, |
219 | NULL); | 220 | NULL); |
220 | |||
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | static int | 224 | static int |
225 | check_blacklist_config (const char *cfg_file, | 225 | check_blacklist_config(const char *cfg_file, |
226 | struct GNUNET_PeerIdentity *peer, | 226 | struct GNUNET_PeerIdentity *peer, |
227 | struct GNUNET_PeerIdentity *bl_peer) | 227 | struct GNUNET_PeerIdentity *bl_peer) |
228 | { | 228 | { |
229 | struct GNUNET_CONFIGURATION_Handle *cfg; | 229 | struct GNUNET_CONFIGURATION_Handle *cfg; |
230 | char *section; | 230 | char *section; |
231 | char *peer_str; | 231 | char *peer_str; |
232 | cfg = GNUNET_CONFIGURATION_create (); | 232 | |
233 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_file)) | 233 | cfg = GNUNET_CONFIGURATION_create(); |
234 | { | 234 | if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfg_file)) |
235 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file); | 235 | { |
236 | GNUNET_CONFIGURATION_destroy (cfg); | 236 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file); |
237 | return GNUNET_SYSERR; | 237 | GNUNET_CONFIGURATION_destroy(cfg); |
238 | } | 238 | return GNUNET_SYSERR; |
239 | 239 | } | |
240 | peer_str = GNUNET_strdup (GNUNET_i2s_full(peer)); | 240 | |
241 | GNUNET_asprintf (§ion, "transport-blacklist-%s", peer_str); | 241 | peer_str = GNUNET_strdup(GNUNET_i2s_full(peer)); |
242 | 242 | GNUNET_asprintf(§ion, "transport-blacklist-%s", peer_str); | |
243 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, section, GNUNET_i2s_full(bl_peer))) | 243 | |
244 | { | 244 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, section, GNUNET_i2s_full(bl_peer))) |
245 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 245 | { |
246 | "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n", | 246 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
247 | cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); | 247 | "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n", |
248 | GNUNET_CONFIGURATION_destroy (cfg); | 248 | cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); |
249 | GNUNET_free (section); | 249 | GNUNET_CONFIGURATION_destroy(cfg); |
250 | GNUNET_free (peer_str); | 250 | GNUNET_free(section); |
251 | return GNUNET_SYSERR; | 251 | GNUNET_free(peer_str); |
252 | } | 252 | return GNUNET_SYSERR; |
253 | } | ||
253 | 254 | ||
254 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 255 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
255 | "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n", | 256 | "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n", |
256 | cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); | 257 | cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); |
257 | 258 | ||
258 | GNUNET_CONFIGURATION_destroy (cfg); | 259 | GNUNET_CONFIGURATION_destroy(cfg); |
259 | GNUNET_free (section); | 260 | GNUNET_free(section); |
260 | GNUNET_free (peer_str); | 261 | GNUNET_free(peer_str); |
261 | return GNUNET_OK; | 262 | return GNUNET_OK; |
262 | } | 263 | } |
263 | 264 | ||
264 | 265 | ||
265 | static void | 266 | static void |
266 | run_stage (void *cls) | 267 | run_stage(void *cls) |
267 | { | 268 | { |
268 | stage_task = NULL; | 269 | stage_task = NULL; |
269 | if (NULL != die_task) | 270 | if (NULL != die_task) |
270 | GNUNET_SCHEDULER_cancel (die_task); | 271 | GNUNET_SCHEDULER_cancel(die_task); |
271 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | 272 | die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); |
272 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage); | 273 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage); |
273 | 274 | ||
274 | if (0 == stage) | 275 | if (0 == stage) |
275 | { | ||
276 | started = GNUNET_NO; | ||
277 | connected = GNUNET_NO; | ||
278 | if (0 == strcmp (test_name, "test_transport_blacklisting_no_bl")) | ||
279 | { | 276 | { |
280 | /* Try to connect peers successfully */ | 277 | started = GNUNET_NO; |
281 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 278 | connected = GNUNET_NO; |
282 | "test_transport_blacklisting_cfg_peer1.conf", | 279 | if (0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) |
283 | 1, | 280 | { |
284 | NULL, | 281 | /* Try to connect peers successfully */ |
285 | NULL, | 282 | p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, |
286 | NULL, | 283 | "test_transport_blacklisting_cfg_peer1.conf", |
287 | NULL, | 284 | 1, |
288 | &start_cb, | 285 | NULL, |
289 | NULL); | 286 | NULL, |
290 | 287 | NULL, | |
291 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 288 | NULL, |
292 | "test_transport_blacklisting_cfg_peer2.conf", | 289 | &start_cb, |
293 | 2, | 290 | NULL); |
294 | NULL, | 291 | |
295 | NULL, | 292 | p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, |
296 | NULL, | 293 | "test_transport_blacklisting_cfg_peer2.conf", |
297 | NULL, | 294 | 2, |
298 | &start_cb, | 295 | NULL, |
299 | NULL); | 296 | NULL, |
297 | NULL, | ||
298 | NULL, | ||
299 | &start_cb, | ||
300 | NULL); | ||
301 | } | ||
302 | else if (0 == strcmp(test_name, | ||
303 | "test_transport_blacklisting_outbound_bl_full")) | ||
304 | { | ||
305 | const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_full.conf"; | ||
306 | const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf"; | ||
307 | |||
308 | p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
309 | cfg_p1, | ||
310 | 1, NULL, NULL, NULL, | ||
311 | NULL, | ||
312 | &start_cb, NULL); | ||
313 | p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
314 | cfg_p2, 2, | ||
315 | NULL, NULL, NULL, | ||
316 | NULL, | ||
317 | &start_cb, NULL); | ||
318 | |||
319 | /* check if configuration contain correct blacklist entries */ | ||
320 | if ((GNUNET_SYSERR == | ||
321 | check_blacklist_config(cfg_p1, &p1->id, &p2->id)) || | ||
322 | (GNUNET_SYSERR == | ||
323 | check_blacklist_config(cfg_p2, &p2->id, &p1->id))) | ||
324 | { | ||
325 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); | ||
326 | p1 = NULL; | ||
327 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); | ||
328 | p2 = NULL; | ||
329 | ok = 1; | ||
330 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
331 | } | ||
332 | } | ||
333 | else if (0 | ||
334 | == strcmp(test_name, "test_transport_blacklisting_outbound_bl_plugin")) | ||
335 | { | ||
336 | const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_plugin.conf"; | ||
337 | const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf"; | ||
338 | |||
339 | p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
340 | cfg_p1, | ||
341 | 1, | ||
342 | NULL, | ||
343 | NULL, | ||
344 | NULL, | ||
345 | NULL, | ||
346 | &start_cb, | ||
347 | NULL); | ||
348 | |||
349 | p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
350 | cfg_p2, 2, | ||
351 | NULL, | ||
352 | NULL, | ||
353 | NULL, | ||
354 | NULL, | ||
355 | &start_cb, | ||
356 | NULL); | ||
357 | |||
358 | /* check if configuration contain correct blacklist entries */ | ||
359 | if ((GNUNET_SYSERR == | ||
360 | check_blacklist_config(cfg_p1, &p1->id, &p2->id)) || | ||
361 | (GNUNET_SYSERR == | ||
362 | check_blacklist_config(cfg_p2, &p2->id, &p1->id))) | ||
363 | { | ||
364 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); | ||
365 | p1 = NULL; | ||
366 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); | ||
367 | p2 = NULL; | ||
368 | ok = 1; | ||
369 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
370 | } | ||
371 | } | ||
372 | else if (0 == strcmp(test_name, | ||
373 | "test_transport_blacklisting_inbound_bl_full")) | ||
374 | { | ||
375 | const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; | ||
376 | const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf"; | ||
377 | |||
378 | p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
379 | cfg_p1, 1, | ||
380 | NULL, | ||
381 | NULL, NULL, NULL, | ||
382 | &start_cb, NULL); | ||
383 | |||
384 | p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
385 | cfg_p2, 2, | ||
386 | NULL, | ||
387 | NULL, NULL, NULL, | ||
388 | &start_cb, NULL); | ||
389 | |||
390 | /* check if configuration contain correct blacklist entries */ | ||
391 | if ((GNUNET_SYSERR == | ||
392 | check_blacklist_config(cfg_p2, &p2->id, &p1->id))) | ||
393 | { | ||
394 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); | ||
395 | p1 = NULL; | ||
396 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); | ||
397 | p2 = NULL; | ||
398 | ok = 1; | ||
399 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
400 | } | ||
401 | } | ||
402 | else if (0 == strcmp(test_name, | ||
403 | "test_transport_blacklisting_inbound_bl_plugin")) | ||
404 | { | ||
405 | const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; | ||
406 | const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf"; | ||
407 | |||
408 | p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
409 | cfg_p1, 1, | ||
410 | NULL, | ||
411 | NULL, NULL, NULL, | ||
412 | &start_cb, NULL); | ||
413 | |||
414 | p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
415 | cfg_p2, 2, | ||
416 | NULL, | ||
417 | NULL, NULL, | ||
418 | NULL, | ||
419 | &start_cb, NULL); | ||
420 | |||
421 | /* check if configuration contain correct blacklist entries */ | ||
422 | if ((GNUNET_SYSERR == | ||
423 | check_blacklist_config(cfg_p2, &p2->id, &p1->id))) | ||
424 | { | ||
425 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); | ||
426 | p1 = NULL; | ||
427 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); | ||
428 | p2 = NULL; | ||
429 | ok = 1; | ||
430 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
431 | } | ||
432 | } | ||
433 | else if (0 == strcmp(test_name, | ||
434 | "test_transport_blacklisting_multiple_plugins")) | ||
435 | { | ||
436 | const char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf"; | ||
437 | const char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf"; | ||
438 | |||
439 | p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
440 | cfg_p1, 1, | ||
441 | NULL, | ||
442 | NULL, NULL, NULL, | ||
443 | &start_cb, NULL); | ||
444 | |||
445 | p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, | ||
446 | cfg_p2, 2, | ||
447 | NULL, | ||
448 | NULL, NULL, NULL, | ||
449 | &start_cb, NULL); | ||
450 | |||
451 | /* check if configuration contain correct blacklist entries */ | ||
452 | if ((GNUNET_SYSERR == | ||
453 | check_blacklist_config(cfg_p1, &p1->id, &p2->id)) || | ||
454 | (GNUNET_SYSERR == | ||
455 | check_blacklist_config(cfg_p2, &p2->id, &p1->id))) | ||
456 | { | ||
457 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); | ||
458 | p1 = NULL; | ||
459 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); | ||
460 | p2 = NULL; | ||
461 | ok = 1; | ||
462 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
463 | } | ||
464 | } | ||
465 | else | ||
466 | { | ||
467 | GNUNET_break(0); | ||
468 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
469 | } | ||
470 | |||
471 | if ((NULL == p1) || (NULL == p2)) | ||
472 | { | ||
473 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n"); | ||
474 | ok = 1; | ||
475 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
476 | } | ||
477 | |||
478 | timeout_task = GNUNET_SCHEDULER_add_delayed(CONNECT_TIMEOUT, | ||
479 | &connect_timeout, | ||
480 | NULL); | ||
481 | stage++; | ||
482 | return; | ||
300 | } | 483 | } |
301 | else if (0 == strcmp (test_name, | ||
302 | "test_transport_blacklisting_outbound_bl_full")) | ||
303 | { | ||
304 | const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_full.conf"; | ||
305 | const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf"; | ||
306 | |||
307 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
308 | cfg_p1, | ||
309 | 1, NULL, NULL, NULL, | ||
310 | NULL, | ||
311 | &start_cb, NULL); | ||
312 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
313 | cfg_p2, 2, | ||
314 | NULL, NULL, NULL, | ||
315 | NULL, | ||
316 | &start_cb, NULL); | ||
317 | |||
318 | /* check if configuration contain correct blacklist entries */ | ||
319 | if ( (GNUNET_SYSERR == | ||
320 | check_blacklist_config (cfg_p1, &p1->id, &p2->id)) || | ||
321 | (GNUNET_SYSERR == | ||
322 | check_blacklist_config (cfg_p2, &p2->id, &p1->id)) ) | ||
323 | { | ||
324 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
325 | p1 = NULL; | ||
326 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
327 | p2 = NULL; | ||
328 | ok = 1; | ||
329 | GNUNET_SCHEDULER_add_now (&end, NULL ); | ||
330 | } | ||
331 | 484 | ||
332 | } | 485 | if (cc != NULL) |
333 | else if (0 | ||
334 | == strcmp (test_name, "test_transport_blacklisting_outbound_bl_plugin")) | ||
335 | { | ||
336 | const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_plugin.conf"; | ||
337 | const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf"; | ||
338 | |||
339 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
340 | cfg_p1, | ||
341 | 1, | ||
342 | NULL, | ||
343 | NULL, | ||
344 | NULL, | ||
345 | NULL, | ||
346 | &start_cb, | ||
347 | NULL); | ||
348 | |||
349 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
350 | cfg_p2, 2, | ||
351 | NULL, | ||
352 | NULL, | ||
353 | NULL, | ||
354 | NULL, | ||
355 | &start_cb, | ||
356 | NULL); | ||
357 | |||
358 | /* check if configuration contain correct blacklist entries */ | ||
359 | if ( (GNUNET_SYSERR == | ||
360 | check_blacklist_config (cfg_p1, &p1->id, &p2->id)) || | ||
361 | (GNUNET_SYSERR == | ||
362 | check_blacklist_config (cfg_p2, &p2->id, &p1->id)) ) | ||
363 | { | ||
364 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
365 | p1 = NULL; | ||
366 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
367 | p2 = NULL; | ||
368 | ok = 1; | ||
369 | GNUNET_SCHEDULER_add_now (&end, NULL ); | ||
370 | } | ||
371 | } | ||
372 | else if (0 == strcmp (test_name, | ||
373 | "test_transport_blacklisting_inbound_bl_full")) | ||
374 | { | 486 | { |
375 | const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; | 487 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); |
376 | const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf"; | 488 | cc = NULL; |
377 | |||
378 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
379 | cfg_p1, 1, | ||
380 | NULL, | ||
381 | NULL, NULL, NULL, | ||
382 | &start_cb, NULL); | ||
383 | |||
384 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
385 | cfg_p2, 2, | ||
386 | NULL, | ||
387 | NULL, NULL, NULL, | ||
388 | &start_cb, NULL); | ||
389 | |||
390 | /* check if configuration contain correct blacklist entries */ | ||
391 | if ( (GNUNET_SYSERR == | ||
392 | check_blacklist_config (cfg_p2, &p2->id, &p1->id)) ) | ||
393 | { | ||
394 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
395 | p1 = NULL; | ||
396 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
397 | p2 = NULL; | ||
398 | ok = 1; | ||
399 | GNUNET_SCHEDULER_add_now (&end, NULL ); | ||
400 | } | ||
401 | } | 489 | } |
402 | else if (0 == strcmp (test_name, | ||
403 | "test_transport_blacklisting_inbound_bl_plugin")) | ||
404 | { | ||
405 | const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; | ||
406 | const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf"; | ||
407 | |||
408 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
409 | cfg_p1, 1, | ||
410 | NULL, | ||
411 | NULL, NULL, NULL, | ||
412 | &start_cb, NULL); | ||
413 | |||
414 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
415 | cfg_p2, 2, | ||
416 | NULL, | ||
417 | NULL, NULL, | ||
418 | NULL, | ||
419 | &start_cb, NULL); | ||
420 | |||
421 | /* check if configuration contain correct blacklist entries */ | ||
422 | if ( (GNUNET_SYSERR == | ||
423 | check_blacklist_config (cfg_p2, &p2->id, &p1->id)) ) | ||
424 | { | ||
425 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
426 | p1 = NULL; | ||
427 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
428 | p2 = NULL; | ||
429 | ok = 1; | ||
430 | GNUNET_SCHEDULER_add_now (&end, NULL ); | ||
431 | } | ||
432 | 490 | ||
433 | } | 491 | if (p1 != NULL) |
434 | else if (0 == strcmp (test_name, | ||
435 | "test_transport_blacklisting_multiple_plugins")) | ||
436 | { | 492 | { |
437 | const char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf"; | 493 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); |
438 | const char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf"; | 494 | p1 = NULL; |
439 | |||
440 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
441 | cfg_p1, 1, | ||
442 | NULL, | ||
443 | NULL, NULL, NULL, | ||
444 | &start_cb, NULL); | ||
445 | |||
446 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
447 | cfg_p2, 2, | ||
448 | NULL, | ||
449 | NULL, NULL, NULL, | ||
450 | &start_cb, NULL); | ||
451 | |||
452 | /* check if configuration contain correct blacklist entries */ | ||
453 | if ( (GNUNET_SYSERR == | ||
454 | check_blacklist_config (cfg_p1, &p1->id, &p2->id)) || | ||
455 | (GNUNET_SYSERR == | ||
456 | check_blacklist_config (cfg_p2, &p2->id, &p1->id))) | ||
457 | { | ||
458 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
459 | p1 = NULL; | ||
460 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
461 | p2 = NULL; | ||
462 | ok = 1; | ||
463 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
464 | } | ||
465 | } | 495 | } |
466 | else | 496 | if (p2 != NULL) |
467 | { | 497 | { |
468 | GNUNET_break (0); | 498 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); |
469 | GNUNET_SCHEDULER_add_now (&end, NULL); | 499 | p2 = NULL; |
470 | } | 500 | } |
471 | 501 | ||
472 | if ((NULL == p1) || (NULL == p2)) | ||
473 | { | ||
474 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n"); | ||
475 | ok = 1; | ||
476 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
477 | } | ||
478 | |||
479 | timeout_task = GNUNET_SCHEDULER_add_delayed (CONNECT_TIMEOUT, | ||
480 | &connect_timeout, | ||
481 | NULL); | ||
482 | stage++; | ||
483 | return; | ||
484 | } | ||
485 | |||
486 | if (cc != NULL ) | ||
487 | { | ||
488 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
489 | cc = NULL; | ||
490 | } | ||
491 | |||
492 | if (p1 != NULL ) | ||
493 | { | ||
494 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
495 | p1 = NULL; | ||
496 | } | ||
497 | if (p2 != NULL ) | ||
498 | { | ||
499 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
500 | p2 = NULL; | ||
501 | } | ||
502 | |||
503 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n", | 502 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n", |
504 | stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED", | 503 | stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED", |
505 | (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED"); | 504 | (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED"); |
506 | 505 | ||
507 | if ((0 == strcmp (test_name, "test_transport_blacklisting_no_bl")) | 506 | if ((0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) |
508 | || (0 == strcmp (test_name, "test_transport_blacklisting_multiple_plugins"))) | 507 | || (0 == strcmp(test_name, "test_transport_blacklisting_multiple_plugins"))) |
509 | { | ||
510 | if ((GNUNET_NO != started) && (GNUNET_YES == connected)) | ||
511 | ok = 0; | ||
512 | else | ||
513 | { | 508 | { |
514 | GNUNET_break(0); | 509 | if ((GNUNET_NO != started) && (GNUNET_YES == connected)) |
515 | ok = 1; | 510 | ok = 0; |
511 | else | ||
512 | { | ||
513 | GNUNET_break(0); | ||
514 | ok = 1; | ||
515 | } | ||
516 | } | 516 | } |
517 | } | ||
518 | else | 517 | else |
519 | { | ||
520 | if ((GNUNET_NO != started) && (GNUNET_YES != connected)) | ||
521 | ok = 0; | ||
522 | else | ||
523 | { | 518 | { |
524 | ok = 1; | 519 | if ((GNUNET_NO != started) && (GNUNET_YES != connected)) |
520 | ok = 0; | ||
521 | else | ||
522 | { | ||
523 | ok = 1; | ||
524 | } | ||
525 | } | 525 | } |
526 | } | 526 | GNUNET_SCHEDULER_add_now(&end, NULL); |
527 | GNUNET_SCHEDULER_add_now (&end, NULL ); | ||
528 | } | 527 | } |
529 | 528 | ||
530 | static void | 529 | static void |
@@ -534,7 +533,7 @@ run(void *cls, char * const *args, const char *cfgfile, | |||
534 | connected = GNUNET_NO; | 533 | connected = GNUNET_NO; |
535 | stage = 0; | 534 | stage = 0; |
536 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name); | 535 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name); |
537 | stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL ); | 536 | stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL); |
538 | } | 537 | } |
539 | 538 | ||
540 | int | 539 | int |
@@ -542,21 +541,21 @@ main(int argc, char *argv0[]) | |||
542 | { | 541 | { |
543 | ok = 1; | 542 | ok = 1; |
544 | 543 | ||
545 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0[0]); | 544 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0[0]); |
546 | 545 | ||
547 | GNUNET_log_setup ("test-transport-api-blacklisting", "WARNING", NULL ); | 546 | GNUNET_log_setup("test-transport-api-blacklisting", "WARNING", NULL); |
548 | 547 | ||
549 | static char * const argv[] = | 548 | static char * const argv[] = |
550 | { "date", "-c", "test_transport_api_data.conf", NULL }; | 549 | { "date", "-c", "test_transport_api_data.conf", NULL }; |
551 | static struct GNUNET_GETOPT_CommandLineOption options[] = | 550 | static struct GNUNET_GETOPT_CommandLineOption options[] = |
552 | { GNUNET_GETOPT_OPTION_END }; | 551 | { GNUNET_GETOPT_OPTION_END }; |
553 | 552 | ||
554 | tth = GNUNET_TRANSPORT_TESTING_init (); | 553 | tth = GNUNET_TRANSPORT_TESTING_init(); |
555 | 554 | ||
556 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, argv, | 555 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, argv, |
557 | "test-transport-api-blacklisting", "nohelp", options, &run, NULL ); | 556 | "test-transport-api-blacklisting", "nohelp", options, &run, NULL); |
558 | 557 | ||
559 | GNUNET_TRANSPORT_TESTING_done (tth); | 558 | GNUNET_TRANSPORT_TESTING_done(tth); |
560 | 559 | ||
561 | return ok; | 560 | return ok; |
562 | } | 561 | } |