diff options
Diffstat (limited to 'src/dv/test_transport_api_dv.c')
-rw-r--r-- | src/dv/test_transport_api_dv.c | 1154 |
1 files changed, 617 insertions, 537 deletions
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c index 8b42c4311..5d9d367e1 100644 --- a/src/dv/test_transport_api_dv.c +++ b/src/dv/test_transport_api_dv.c | |||
@@ -93,11 +93,12 @@ static int transmit_ready_called; | |||
93 | 93 | ||
94 | static enum GNUNET_TESTING_Topology topology; | 94 | static enum GNUNET_TESTING_Topology topology; |
95 | 95 | ||
96 | static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */ | 96 | static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */ |
97 | 97 | ||
98 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ | 98 | static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ |
99 | 99 | ||
100 | static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; | 100 | static enum GNUNET_TESTING_TopologyOption connect_topology_option = |
101 | GNUNET_TESTING_TOPOLOGY_OPTION_ALL; | ||
101 | 102 | ||
102 | static double connect_topology_option_modifier = 0.0; | 103 | static double connect_topology_option_modifier = 0.0; |
103 | 104 | ||
@@ -167,25 +168,23 @@ static struct TestMessageContext *other_test_messages; | |||
167 | /** | 168 | /** |
168 | * Check whether peers successfully shut down. | 169 | * Check whether peers successfully shut down. |
169 | */ | 170 | */ |
170 | void shutdown_callback (void *cls, | 171 | void |
171 | const char *emsg) | 172 | shutdown_callback (void *cls, const char *emsg) |
172 | { | 173 | { |
173 | if (emsg != NULL) | 174 | if (emsg != NULL) |
174 | { | 175 | { |
175 | #if VERBOSE | 176 | #if VERBOSE |
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); |
177 | "Shutdown of peers failed!\n"); | ||
178 | #endif | 178 | #endif |
179 | if (ok == 0) | 179 | if (ok == 0) |
180 | ok = 666; | 180 | ok = 666; |
181 | } | 181 | } |
182 | else | 182 | else |
183 | { | 183 | { |
184 | #if VERBOSE | 184 | #if VERBOSE |
185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); |
186 | "All peers successfully shut down!\n"); | ||
187 | #endif | 186 | #endif |
188 | } | 187 | } |
189 | } | 188 | } |
190 | 189 | ||
191 | static void | 190 | static void |
@@ -203,100 +202,102 @@ finish_testing () | |||
203 | #endif | 202 | #endif |
204 | peer_pos = all_peers; | 203 | peer_pos = all_peers; |
205 | while (peer_pos != NULL) | 204 | while (peer_pos != NULL) |
206 | { | 205 | { |
207 | if (peer_pos->peer_handle != NULL) | 206 | if (peer_pos->peer_handle != NULL) |
208 | GNUNET_CORE_disconnect(peer_pos->peer_handle); | 207 | GNUNET_CORE_disconnect (peer_pos->peer_handle); |
209 | free_peer_pos = peer_pos; | 208 | free_peer_pos = peer_pos; |
210 | peer_pos = peer_pos->next; | 209 | peer_pos = peer_pos->next; |
211 | GNUNET_free(free_peer_pos); | 210 | GNUNET_free (free_peer_pos); |
212 | } | 211 | } |
213 | all_peers = NULL; | 212 | all_peers = NULL; |
214 | 213 | ||
215 | pos = test_messages; | 214 | pos = test_messages; |
216 | while (pos != NULL) | 215 | while (pos != NULL) |
216 | { | ||
217 | if (pos->peer1handle != NULL) | ||
217 | { | 218 | { |
218 | if (pos->peer1handle != NULL) | 219 | GNUNET_CORE_disconnect (pos->peer1handle); |
219 | { | 220 | pos->peer1handle = NULL; |
220 | GNUNET_CORE_disconnect(pos->peer1handle); | ||
221 | pos->peer1handle = NULL; | ||
222 | } | ||
223 | if (pos->peer2handle != NULL) | ||
224 | { | ||
225 | GNUNET_CORE_disconnect(pos->peer2handle); | ||
226 | pos->peer2handle = NULL; | ||
227 | } | ||
228 | free_pos = pos; | ||
229 | pos = pos->next; | ||
230 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
231 | { | ||
232 | GNUNET_SCHEDULER_cancel(free_pos->disconnect_task); | ||
233 | } | ||
234 | GNUNET_free(free_pos); | ||
235 | } | 221 | } |
222 | if (pos->peer2handle != NULL) | ||
223 | { | ||
224 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
225 | pos->peer2handle = NULL; | ||
226 | } | ||
227 | free_pos = pos; | ||
228 | pos = pos->next; | ||
229 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
230 | { | ||
231 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); | ||
232 | } | ||
233 | GNUNET_free (free_pos); | ||
234 | } | ||
236 | 235 | ||
237 | pos = other_test_messages; | 236 | pos = other_test_messages; |
238 | while (pos != NULL) | 237 | while (pos != NULL) |
238 | { | ||
239 | if (pos->peer1handle != NULL) | ||
240 | { | ||
241 | GNUNET_CORE_disconnect (pos->peer1handle); | ||
242 | pos->peer1handle = NULL; | ||
243 | } | ||
244 | if (pos->peer2handle != NULL) | ||
245 | { | ||
246 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
247 | pos->peer2handle = NULL; | ||
248 | } | ||
249 | free_pos = pos; | ||
250 | pos = pos->next; | ||
251 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
239 | { | 252 | { |
240 | if (pos->peer1handle != NULL) | 253 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); |
241 | { | ||
242 | GNUNET_CORE_disconnect(pos->peer1handle); | ||
243 | pos->peer1handle = NULL; | ||
244 | } | ||
245 | if (pos->peer2handle != NULL) | ||
246 | { | ||
247 | GNUNET_CORE_disconnect(pos->peer2handle); | ||
248 | pos->peer2handle = NULL; | ||
249 | } | ||
250 | free_pos = pos; | ||
251 | pos = pos->next; | ||
252 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
253 | { | ||
254 | GNUNET_SCHEDULER_cancel(free_pos->disconnect_task); | ||
255 | } | ||
256 | GNUNET_free(free_pos); | ||
257 | } | 254 | } |
255 | GNUNET_free (free_pos); | ||
256 | } | ||
258 | #if VERBOSE | 257 | #if VERBOSE |
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
260 | "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called); | 259 | "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", |
260 | transmit_ready_scheduled, transmit_ready_failed, | ||
261 | transmit_ready_called); | ||
261 | #endif | 262 | #endif |
262 | 263 | ||
263 | #if VERBOSE | 264 | #if VERBOSE |
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); |
265 | "Calling daemons_stop\n"); | ||
266 | #endif | 266 | #endif |
267 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 267 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
268 | #if VERBOSE | 268 | #if VERBOSE |
269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n"); |
270 | "daemons_stop finished\n"); | ||
271 | #endif | 270 | #endif |
272 | if (dotOutFile != NULL) | 271 | if (dotOutFile != NULL) |
273 | { | 272 | { |
274 | fprintf(dotOutFile, "}"); | 273 | fprintf (dotOutFile, "}"); |
275 | fclose(dotOutFile); | 274 | fclose (dotOutFile); |
276 | } | 275 | } |
277 | 276 | ||
278 | ok = 0; | 277 | ok = 0; |
279 | } | 278 | } |
280 | 279 | ||
281 | 280 | ||
282 | static void | 281 | static void |
283 | disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 282 | disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
284 | { | 283 | { |
285 | struct TestMessageContext *pos = cls; | 284 | struct TestMessageContext *pos = cls; |
286 | 285 | ||
287 | /* Disconnect from the respective cores */ | 286 | /* Disconnect from the respective cores */ |
288 | #if VERBOSE | 287 | #if VERBOSE |
289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
290 | "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id)); | 289 | "Disconnecting from peer 1 `%4s'\n", |
290 | GNUNET_i2s (&pos->peer1->id)); | ||
291 | #endif | 291 | #endif |
292 | if (pos->peer1handle != NULL) | 292 | if (pos->peer1handle != NULL) |
293 | GNUNET_CORE_disconnect(pos->peer1handle); | 293 | GNUNET_CORE_disconnect (pos->peer1handle); |
294 | #if VERBOSE | 294 | #if VERBOSE |
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id)); | 296 | "Disconnecting from peer 2 `%4s'\n", |
297 | GNUNET_i2s (&pos->peer2->id)); | ||
297 | #endif | 298 | #endif |
298 | if (pos->peer2handle != NULL) | 299 | if (pos->peer2handle != NULL) |
299 | GNUNET_CORE_disconnect(pos->peer2handle); | 300 | GNUNET_CORE_disconnect (pos->peer2handle); |
300 | /* Set handles to NULL so test case can be ended properly */ | 301 | /* Set handles to NULL so test case can be ended properly */ |
301 | pos->peer1handle = NULL; | 302 | pos->peer1handle = NULL; |
302 | pos->peer2handle = NULL; | 303 | pos->peer2handle = NULL; |
@@ -306,84 +307,85 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
306 | } | 307 | } |
307 | 308 | ||
308 | static void | 309 | static void |
309 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 310 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
310 | { | 311 | { |
311 | char *msg = cls; | 312 | char *msg = cls; |
313 | |||
312 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 314 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
313 | "End badly was called (%s)... stopping daemons.\n", msg); | 315 | "End badly was called (%s)... stopping daemons.\n", msg); |
314 | struct TestMessageContext *pos; | 316 | struct TestMessageContext *pos; |
315 | struct TestMessageContext *free_pos; | 317 | struct TestMessageContext *free_pos; |
316 | struct PeerContext * peer_pos; | 318 | struct PeerContext *peer_pos; |
317 | struct PeerContext * free_peer_pos; | 319 | struct PeerContext *free_peer_pos; |
318 | 320 | ||
319 | peer_pos = all_peers; | 321 | peer_pos = all_peers; |
320 | while (peer_pos != NULL) | 322 | while (peer_pos != NULL) |
321 | { | 323 | { |
322 | if (peer_pos->peer_handle != NULL) | 324 | if (peer_pos->peer_handle != NULL) |
323 | GNUNET_CORE_disconnect(peer_pos->peer_handle); | 325 | GNUNET_CORE_disconnect (peer_pos->peer_handle); |
324 | free_peer_pos = peer_pos; | 326 | free_peer_pos = peer_pos; |
325 | peer_pos = peer_pos->next; | 327 | peer_pos = peer_pos->next; |
326 | GNUNET_free(free_peer_pos); | 328 | GNUNET_free (free_peer_pos); |
327 | } | 329 | } |
328 | all_peers = NULL; | 330 | all_peers = NULL; |
329 | 331 | ||
330 | pos = test_messages; | 332 | pos = test_messages; |
331 | while (pos != NULL) | 333 | while (pos != NULL) |
334 | { | ||
335 | if (pos->peer1handle != NULL) | ||
332 | { | 336 | { |
333 | if (pos->peer1handle != NULL) | 337 | GNUNET_CORE_disconnect (pos->peer1handle); |
334 | { | 338 | pos->peer1handle = NULL; |
335 | GNUNET_CORE_disconnect(pos->peer1handle); | ||
336 | pos->peer1handle = NULL; | ||
337 | } | ||
338 | if (pos->peer2handle != NULL) | ||
339 | { | ||
340 | GNUNET_CORE_disconnect(pos->peer2handle); | ||
341 | pos->peer2handle = NULL; | ||
342 | } | ||
343 | free_pos = pos; | ||
344 | pos = pos->next; | ||
345 | GNUNET_free(free_pos); | ||
346 | } | 339 | } |
340 | if (pos->peer2handle != NULL) | ||
341 | { | ||
342 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
343 | pos->peer2handle = NULL; | ||
344 | } | ||
345 | free_pos = pos; | ||
346 | pos = pos->next; | ||
347 | GNUNET_free (free_pos); | ||
348 | } | ||
347 | 349 | ||
348 | pos = other_test_messages; | 350 | pos = other_test_messages; |
349 | while (pos != NULL) | 351 | while (pos != NULL) |
352 | { | ||
353 | if (pos->peer1handle != NULL) | ||
350 | { | 354 | { |
351 | if (pos->peer1handle != NULL) | 355 | GNUNET_CORE_disconnect (pos->peer1handle); |
352 | { | 356 | pos->peer1handle = NULL; |
353 | GNUNET_CORE_disconnect(pos->peer1handle); | ||
354 | pos->peer1handle = NULL; | ||
355 | } | ||
356 | if (pos->peer2handle != NULL) | ||
357 | { | ||
358 | GNUNET_CORE_disconnect(pos->peer2handle); | ||
359 | pos->peer2handle = NULL; | ||
360 | } | ||
361 | free_pos = pos; | ||
362 | pos = pos->next; | ||
363 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
364 | { | ||
365 | GNUNET_SCHEDULER_cancel(free_pos->disconnect_task); | ||
366 | } | ||
367 | GNUNET_free(free_pos); | ||
368 | } | 357 | } |
369 | 358 | if (pos->peer2handle != NULL) | |
370 | if (pg != NULL) | 359 | { |
360 | GNUNET_CORE_disconnect (pos->peer2handle); | ||
361 | pos->peer2handle = NULL; | ||
362 | } | ||
363 | free_pos = pos; | ||
364 | pos = pos->next; | ||
365 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
371 | { | 366 | { |
372 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 367 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); |
373 | ok = 7331; /* Opposite of leet */ | ||
374 | } | 368 | } |
369 | GNUNET_free (free_pos); | ||
370 | } | ||
371 | |||
372 | if (pg != NULL) | ||
373 | { | ||
374 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
375 | ok = 7331; /* Opposite of leet */ | ||
376 | } | ||
375 | else | 377 | else |
376 | ok = 401; /* Never got peers started */ | 378 | ok = 401; /* Never got peers started */ |
377 | 379 | ||
378 | if (dotOutFile != NULL) | 380 | if (dotOutFile != NULL) |
379 | { | 381 | { |
380 | fprintf(dotOutFile, "}"); | 382 | fprintf (dotOutFile, "}"); |
381 | fclose(dotOutFile); | 383 | fclose (dotOutFile); |
382 | } | 384 | } |
383 | } | 385 | } |
384 | 386 | ||
385 | static void | 387 | static void |
386 | send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); | 388 | send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
387 | 389 | ||
388 | /** | 390 | /** |
389 | * Get distance information from 'atsi'. | 391 | * Get distance information from 'atsi'. |
@@ -394,15 +396,15 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); | |||
394 | static uint32_t | 396 | static uint32_t |
395 | get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 397 | get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
396 | { | 398 | { |
397 | while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && | 399 | while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && |
398 | (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) ) | 400 | (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)) |
399 | atsi++; | 401 | atsi++; |
400 | if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) | 402 | if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) |
401 | { | 403 | { |
402 | GNUNET_break (0); | 404 | GNUNET_break (0); |
403 | /* FIXME: we do not have distance data? Assume direct neighbor. */ | 405 | /* FIXME: we do not have distance data? Assume direct neighbor. */ |
404 | return 1; | 406 | return 1; |
405 | } | 407 | } |
406 | return ntohl (atsi->value); | 408 | return ntohl (atsi->value); |
407 | } | 409 | } |
408 | 410 | ||
@@ -413,62 +415,74 @@ process_mtype (void *cls, | |||
413 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 415 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
414 | { | 416 | { |
415 | struct TestMessageContext *pos = cls; | 417 | struct TestMessageContext *pos = cls; |
416 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message; | 418 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message; |
419 | |||
417 | #if VERBOSE | 420 | #if VERBOSE |
418 | uint32_t distance; | 421 | uint32_t distance; |
419 | #endif | 422 | #endif |
420 | if (pos->uid != ntohl(msg->uid)) | 423 | if (pos->uid != ntohl (msg->uid)) |
421 | return GNUNET_OK; | 424 | return GNUNET_OK; |
422 | 425 | ||
423 | #if VERBOSE | 426 | #if VERBOSE |
424 | distance = get_atsi_distance(atsi); | 427 | distance = get_atsi_distance (atsi); |
425 | #endif | 428 | #endif |
426 | GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity))); | 429 | GNUNET_assert (0 == |
430 | memcmp (peer, &pos->peer1->id, | ||
431 | sizeof (struct GNUNET_PeerIdentity))); | ||
427 | if (total_other_expected_messages == 0) | 432 | if (total_other_expected_messages == 0) |
428 | { | 433 | { |
429 | total_messages_received++; | 434 | total_messages_received++; |
430 | #if VERBOSE | 435 | #if VERBOSE |
431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
432 | "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); | 437 | "Received message from `%4s', type %d, uid %u, distance %u.\n", |
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 438 | GNUNET_i2s (peer), ntohs (message->type), ntohl (msg->uid), |
434 | "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); | 439 | distance); |
440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
441 | "Total messages received %d, expected %d.\n", | ||
442 | total_messages_received, expected_messages); | ||
435 | #endif | 443 | #endif |
436 | } | 444 | } |
437 | else | 445 | else |
438 | { | 446 | { |
439 | total_other_messages++; | 447 | total_other_messages++; |
440 | #if VERBOSE | 448 | #if VERBOSE |
441 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
442 | "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); | 450 | "Received message from `%4s', type %d, uid %u, distance %u.\n", |
443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | GNUNET_i2s (peer), ntohs (message->type), ntohl (msg->uid), |
444 | "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages); | 452 | distance); |
453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
454 | "Total messages received %d, expected %d.\n", | ||
455 | total_other_messages, total_other_expected_messages); | ||
445 | #endif | 456 | #endif |
446 | } | 457 | } |
447 | 458 | ||
448 | if ((total_messages_received == expected_messages) && (total_other_messages == 0)) | 459 | if ((total_messages_received == expected_messages) && |
449 | { | 460 | (total_other_messages == 0)) |
450 | GNUNET_SCHEDULER_cancel (die_task); | 461 | { |
451 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 462 | GNUNET_SCHEDULER_cancel (die_task); |
452 | &end_badly, "waiting for DV peers to connect!"); | 463 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
453 | /* | 464 | &end_badly, |
454 | if ((num_peers == 3) && (total_other_expected_messages == 2)) | 465 | "waiting for DV peers to connect!"); |
455 | { | 466 | /* |
456 | GNUNET_SCHEDULER_add_now (&send_other_messages, NULL); | 467 | * if ((num_peers == 3) && (total_other_expected_messages == 2)) |
457 | } | 468 | * { |
458 | else | 469 | * GNUNET_SCHEDULER_add_now (&send_other_messages, NULL); |
459 | { | 470 | * } |
460 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL); | 471 | * else |
461 | }*/ | 472 | * { |
462 | } | 473 | * GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL); |
463 | else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages)) | 474 | * } */ |
464 | { | 475 | } |
465 | GNUNET_SCHEDULER_cancel (die_task); | 476 | else if ((total_other_expected_messages > 0) && |
466 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 477 | (total_other_messages == total_other_expected_messages)) |
467 | } | 478 | { |
479 | GNUNET_SCHEDULER_cancel (die_task); | ||
480 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | ||
481 | } | ||
468 | else | 482 | else |
469 | { | 483 | { |
470 | pos->disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cores, pos); | 484 | pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos); |
471 | } | 485 | } |
472 | 486 | ||
473 | return GNUNET_OK; | 487 | return GNUNET_OK; |
474 | } | 488 | } |
@@ -483,11 +497,13 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
483 | m = (struct GNUNET_TestMessage *) buf; | 497 | m = (struct GNUNET_TestMessage *) buf; |
484 | m->header.type = htons (MTYPE); | 498 | m->header.type = htons (MTYPE); |
485 | m->header.size = htons (sizeof (struct GNUNET_TestMessage)); | 499 | m->header.size = htons (sizeof (struct GNUNET_TestMessage)); |
486 | m->uid = htonl(pos->uid); | 500 | m->uid = htonl (pos->uid); |
487 | transmit_ready_called++; | 501 | transmit_ready_called++; |
488 | #if VERBOSE | 502 | #if VERBOSE |
489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
490 | "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id), transmit_ready_scheduled, transmit_ready_called); | 504 | "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", |
505 | GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled, | ||
506 | transmit_ready_called); | ||
491 | #endif | 507 | #endif |
492 | return sizeof (struct GNUNET_TestMessage); | 508 | return sizeof (struct GNUNET_TestMessage); |
493 | } | 509 | } |
@@ -510,47 +526,50 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
510 | * @param peer peer identity this notification is about | 526 | * @param peer peer identity this notification is about |
511 | * @param atsi performance data for the connection | 527 | * @param atsi performance data for the connection |
512 | */ | 528 | */ |
513 | static void connect_notify_peer2 (void *cls, | 529 | static void |
514 | const struct | 530 | connect_notify_peer2 (void *cls, |
515 | GNUNET_PeerIdentity *peer, | 531 | const struct |
516 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 532 | GNUNET_PeerIdentity *peer, |
533 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
517 | { | 534 | { |
518 | struct TestMessageContext *pos = cls; | 535 | struct TestMessageContext *pos = cls; |
519 | 536 | ||
520 | if (0 == memcmp(&pos->peer1->id, peer, sizeof(struct GNUNET_PeerIdentity))) | 537 | if (0 == memcmp (&pos->peer1->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
521 | { | 538 | { |
522 | #if VERBOSE | 539 | #if VERBOSE |
523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 540 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
524 | "Core connection from `%s' to `%4s' verfied, sending message!\n", | 541 | "Core connection from `%s' to `%4s' verfied, sending message!\n", |
525 | GNUNET_i2s(&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey)); | 542 | GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey)); |
526 | #endif | 543 | #endif |
527 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, | 544 | if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, |
528 | GNUNET_YES, | 545 | GNUNET_YES, |
529 | 0, | 546 | 0, |
530 | TIMEOUT, | 547 | TIMEOUT, |
531 | &pos->peer2->id, | 548 | &pos->peer2->id, |
532 | sizeof (struct GNUNET_TestMessage), | 549 | sizeof (struct |
533 | &transmit_ready, pos)) | 550 | GNUNET_TestMessage), |
534 | { | 551 | &transmit_ready, pos)) |
535 | /* This probably shouldn't happen, but it does (timing issue?) */ | 552 | { |
536 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 553 | /* This probably shouldn't happen, but it does (timing issue?) */ |
537 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | 554 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
538 | GNUNET_i2s (&pos->peer2->id)); | 555 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
539 | transmit_ready_failed++; | 556 | GNUNET_i2s (&pos->peer2->id)); |
540 | total_other_expected_messages--; | 557 | transmit_ready_failed++; |
541 | } | 558 | total_other_expected_messages--; |
542 | else | ||
543 | { | ||
544 | transmit_ready_scheduled++; | ||
545 | } | ||
546 | } | 559 | } |
560 | else | ||
561 | { | ||
562 | transmit_ready_scheduled++; | ||
563 | } | ||
564 | } | ||
547 | } | 565 | } |
548 | 566 | ||
549 | static void | 567 | static void |
550 | init_notify_peer2 (void *cls, | 568 | init_notify_peer2 (void *cls, |
551 | struct GNUNET_CORE_Handle *server, | 569 | struct GNUNET_CORE_Handle *server, |
552 | const struct GNUNET_PeerIdentity *my_identity, | 570 | const struct GNUNET_PeerIdentity *my_identity, |
553 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 571 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
572 | *publicKey) | ||
554 | { | 573 | { |
555 | #if VERBOSE | 574 | #if VERBOSE |
556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -568,39 +587,42 @@ init_notify_peer2 (void *cls, | |||
568 | * @param peer peer identity this notification is about | 587 | * @param peer peer identity this notification is about |
569 | * @param atsi performance data for the connection | 588 | * @param atsi performance data for the connection |
570 | */ | 589 | */ |
571 | static void connect_notify_peer1 (void *cls, | 590 | static void |
572 | const struct | 591 | connect_notify_peer1 (void *cls, |
573 | GNUNET_PeerIdentity *peer, | 592 | const struct |
574 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 593 | GNUNET_PeerIdentity *peer, |
594 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
575 | { | 595 | { |
576 | struct TestMessageContext *pos = cls; | 596 | struct TestMessageContext *pos = cls; |
577 | 597 | ||
578 | if (0 == memcmp(&pos->peer2->id, peer, sizeof(struct GNUNET_PeerIdentity))) | 598 | if (0 == memcmp (&pos->peer2->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
579 | { | 599 | { |
580 | #if VERBOSE | 600 | #if VERBOSE |
581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
582 | "Core connection from `%s' to `%4s' verified.\n", | 602 | "Core connection from `%s' to `%4s' verified.\n", |
583 | GNUNET_i2s(&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey)); | 603 | GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey)); |
584 | #endif | 604 | #endif |
585 | /* | 605 | /* |
586 | * Connect to the receiving peer | 606 | * Connect to the receiving peer |
587 | */ | 607 | */ |
588 | pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, | 608 | pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, |
589 | 1, | 609 | 1, |
590 | pos, | 610 | pos, |
591 | &init_notify_peer2, | 611 | &init_notify_peer2, |
592 | &connect_notify_peer2, | 612 | &connect_notify_peer2, |
593 | NULL, | 613 | NULL, |
594 | NULL, NULL, | 614 | NULL, NULL, |
595 | GNUNET_YES, NULL, GNUNET_YES, handlers); | 615 | GNUNET_YES, NULL, GNUNET_YES, |
596 | } | 616 | handlers); |
617 | } | ||
597 | } | 618 | } |
598 | 619 | ||
599 | static void | 620 | static void |
600 | init_notify_peer1 (void *cls, | 621 | init_notify_peer1 (void *cls, |
601 | struct GNUNET_CORE_Handle *server, | 622 | struct GNUNET_CORE_Handle *server, |
602 | const struct GNUNET_PeerIdentity *my_identity, | 623 | const struct GNUNET_PeerIdentity *my_identity, |
603 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 624 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
625 | *publicKey) | ||
604 | { | 626 | { |
605 | total_server_connections++; | 627 | total_server_connections++; |
606 | #if VERBOSE | 628 | #if VERBOSE |
@@ -612,129 +634,142 @@ init_notify_peer1 (void *cls, | |||
612 | 634 | ||
613 | 635 | ||
614 | static void | 636 | static void |
615 | send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 637 | send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
616 | { | 638 | { |
617 | struct TestMessageContext *pos = cls; | 639 | struct TestMessageContext *pos = cls; |
618 | 640 | ||
619 | if (( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL)) | 641 | if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL)) |
620 | return; | 642 | return; |
621 | 643 | ||
622 | if (die_task == GNUNET_SCHEDULER_NO_TASK) | 644 | if (die_task == GNUNET_SCHEDULER_NO_TASK) |
623 | { | 645 | { |
624 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 646 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
625 | &end_badly, "from create topology (timeout)"); | 647 | &end_badly, |
626 | } | 648 | "from create topology (timeout)"); |
649 | } | ||
627 | 650 | ||
628 | if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) | 651 | if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) |
629 | { | 652 | { |
630 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), | 653 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
631 | &send_test_messages, pos); | 654 | (GNUNET_TIME_UNIT_SECONDS, 1), |
632 | return; /* Otherwise we'll double schedule messages here! */ | 655 | &send_test_messages, pos); |
633 | } | 656 | return; /* Otherwise we'll double schedule messages here! */ |
657 | } | ||
634 | #if VERBOSE | 658 | #if VERBOSE |
635 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname); | 659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
660 | "Attempting to send test message from %s to %s\n", | ||
661 | pos->peer1->shortname, pos->peer2->shortname); | ||
636 | #endif | 662 | #endif |
637 | /* | 663 | /* |
638 | * Connect to the sending peer | 664 | * Connect to the sending peer |
639 | */ | 665 | */ |
640 | pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, | 666 | pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, |
641 | 1, | 667 | 1, |
642 | pos, | 668 | pos, |
643 | &init_notify_peer1, | 669 | &init_notify_peer1, |
644 | &connect_notify_peer1, | 670 | &connect_notify_peer1, |
645 | NULL, | 671 | NULL, |
646 | NULL, | 672 | NULL, |
647 | NULL, | 673 | NULL, |
648 | GNUNET_NO, NULL, GNUNET_NO, no_handlers); | 674 | GNUNET_NO, NULL, GNUNET_NO, |
675 | no_handlers); | ||
649 | 676 | ||
650 | GNUNET_assert(pos->peer1handle != NULL); | 677 | GNUNET_assert (pos->peer1handle != NULL); |
651 | 678 | ||
652 | if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) | 679 | if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) |
653 | { | 680 | { |
654 | GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); | 681 | GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); |
655 | } | 682 | } |
656 | else | 683 | else |
657 | { | 684 | { |
658 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), | 685 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
659 | &send_test_messages, pos->next); | 686 | (GNUNET_TIME_UNIT_SECONDS, 1), |
660 | } | 687 | &send_test_messages, pos->next); |
688 | } | ||
661 | } | 689 | } |
662 | 690 | ||
663 | static void | 691 | static void |
664 | send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 692 | send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
665 | { | 693 | { |
666 | struct TestMessageContext *pos; | 694 | struct TestMessageContext *pos; |
667 | struct TestMessageContext *free_pos; | 695 | struct TestMessageContext *free_pos; |
668 | struct PeerContext *peer_pos; | 696 | struct PeerContext *peer_pos; |
697 | |||
669 | #if TEST_ALL | 698 | #if TEST_ALL |
670 | struct PeerContext *inner_peer_pos; | 699 | struct PeerContext *inner_peer_pos; |
671 | struct TestMessageContext *temp_context; | 700 | struct TestMessageContext *temp_context; |
672 | #endif | 701 | #endif |
673 | peer_pos = all_peers; | 702 | peer_pos = all_peers; |
674 | while (peer_pos != NULL) | 703 | while (peer_pos != NULL) |
704 | { | ||
705 | if (peer_pos->peer_handle != NULL) | ||
675 | { | 706 | { |
676 | if (peer_pos->peer_handle != NULL) | 707 | GNUNET_CORE_disconnect (peer_pos->peer_handle); |
677 | { | 708 | peer_pos->peer_handle = NULL; |
678 | GNUNET_CORE_disconnect(peer_pos->peer_handle); | 709 | } |
679 | peer_pos->peer_handle = NULL; | ||
680 | } | ||
681 | #if TEST_ALL | 710 | #if TEST_ALL |
682 | inner_peer_pos = all_peers; | 711 | inner_peer_pos = all_peers; |
683 | while (inner_peer_pos != NULL) | 712 | while (inner_peer_pos != NULL) |
684 | { | 713 | { |
685 | if (inner_peer_pos != peer_pos) | 714 | if (inner_peer_pos != peer_pos) |
686 | { | 715 | { |
687 | temp_total_other_messages++; | 716 | temp_total_other_messages++; |
688 | temp_context = GNUNET_malloc(sizeof(struct TestMessageContext)); | 717 | temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); |
689 | temp_context->peer1 = peer_pos->daemon; | 718 | temp_context->peer1 = peer_pos->daemon; |
690 | temp_context->peer2 = inner_peer_pos->daemon; | 719 | temp_context->peer2 = inner_peer_pos->daemon; |
691 | temp_context->next = other_test_messages; | 720 | temp_context->next = other_test_messages; |
692 | temp_context->uid = total_connections + temp_total_other_messages; | 721 | temp_context->uid = total_connections + temp_total_other_messages; |
693 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 722 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
694 | other_test_messages = temp_context; | 723 | other_test_messages = temp_context; |
695 | } | 724 | } |
696 | inner_peer_pos = inner_peer_pos->next; | 725 | inner_peer_pos = inner_peer_pos->next; |
697 | } | ||
698 | #endif | ||
699 | peer_pos = peer_pos->next; | ||
700 | } | 726 | } |
727 | #endif | ||
728 | peer_pos = peer_pos->next; | ||
729 | } | ||
701 | all_peers = NULL; | 730 | all_peers = NULL; |
702 | 731 | ||
703 | pos = test_messages; | 732 | pos = test_messages; |
704 | while (pos != NULL) | 733 | while (pos != NULL) |
734 | { | ||
735 | if (pos->peer1handle != NULL) | ||
736 | { | ||
737 | GNUNET_CORE_disconnect (pos->peer1handle); | ||
738 | pos->peer1handle = NULL; | ||
739 | } | ||
740 | if (pos->peer2handle != NULL) | ||
705 | { | 741 | { |
706 | if (pos->peer1handle != NULL) | 742 | GNUNET_CORE_disconnect (pos->peer2handle); |
707 | { | 743 | pos->peer2handle = NULL; |
708 | GNUNET_CORE_disconnect(pos->peer1handle); | ||
709 | pos->peer1handle = NULL; | ||
710 | } | ||
711 | if (pos->peer2handle != NULL) | ||
712 | { | ||
713 | GNUNET_CORE_disconnect(pos->peer2handle); | ||
714 | pos->peer2handle = NULL; | ||
715 | } | ||
716 | free_pos = pos; | ||
717 | pos = pos->next; | ||
718 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
719 | { | ||
720 | GNUNET_SCHEDULER_cancel(free_pos->disconnect_task); | ||
721 | } | ||
722 | GNUNET_free(free_pos); | ||
723 | } | 744 | } |
745 | free_pos = pos; | ||
746 | pos = pos->next; | ||
747 | if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
748 | { | ||
749 | GNUNET_SCHEDULER_cancel (free_pos->disconnect_task); | ||
750 | } | ||
751 | GNUNET_free (free_pos); | ||
752 | } | ||
724 | test_messages = NULL; | 753 | test_messages = NULL; |
725 | 754 | ||
726 | total_other_expected_messages = temp_total_other_messages; | 755 | total_other_expected_messages = temp_total_other_messages; |
727 | if (total_other_expected_messages == 0) | 756 | if (total_other_expected_messages == 0) |
728 | { | 757 | { |
729 | GNUNET_SCHEDULER_add_now (&end_badly, "send_other_messages had 0 messages to send, no DV connections made!"); | 758 | GNUNET_SCHEDULER_add_now (&end_badly, |
730 | } | 759 | "send_other_messages had 0 messages to send, no DV connections made!"); |
760 | } | ||
731 | #if VERBOSE | 761 | #if VERBOSE |
732 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test messages\n", total_other_expected_messages); | 762 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
763 | "Preparing to send %d other test messages\n", | ||
764 | total_other_expected_messages); | ||
733 | #endif | 765 | #endif |
734 | 766 | ||
735 | GNUNET_SCHEDULER_add_now (&send_test_messages, other_test_messages); | 767 | GNUNET_SCHEDULER_add_now (&send_test_messages, other_test_messages); |
736 | GNUNET_SCHEDULER_cancel(die_task); | 768 | GNUNET_SCHEDULER_cancel (die_task); |
737 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages"); | 769 | die_task = |
770 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
771 | (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, | ||
772 | "from send_other_messages"); | ||
738 | } | 773 | } |
739 | 774 | ||
740 | static void | 775 | static void |
@@ -749,68 +784,73 @@ topology_callback (void *cls, | |||
749 | const char *emsg) | 784 | const char *emsg) |
750 | { | 785 | { |
751 | struct TestMessageContext *temp_context; | 786 | struct TestMessageContext *temp_context; |
787 | |||
752 | if (emsg == NULL) | 788 | if (emsg == NULL) |
753 | { | 789 | { |
754 | total_connections++; | 790 | total_connections++; |
755 | #if VERBOSE | 791 | #if VERBOSE |
756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", | 792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
757 | first_daemon->shortname, | 793 | "connected peer %s to peer %s, distance %u\n", |
758 | second_daemon->shortname, | 794 | first_daemon->shortname, second_daemon->shortname, distance); |
759 | distance); | ||
760 | #endif | 795 | #endif |
761 | temp_context = GNUNET_malloc(sizeof(struct TestMessageContext)); | 796 | temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); |
762 | temp_context->peer1 = first_daemon; | 797 | temp_context->peer1 = first_daemon; |
763 | temp_context->peer2 = second_daemon; | 798 | temp_context->peer2 = second_daemon; |
764 | temp_context->next = test_messages; | 799 | temp_context->next = test_messages; |
765 | temp_context->uid = total_connections; | 800 | temp_context->uid = total_connections; |
766 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 801 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
767 | test_messages = temp_context; | 802 | test_messages = temp_context; |
768 | expected_messages++; | 803 | expected_messages++; |
769 | } | 804 | } |
770 | #if VERBOSE | 805 | #if VERBOSE |
771 | else | 806 | else |
772 | { | 807 | { |
773 | failed_connections++; | 808 | failed_connections++; |
774 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", | 809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
775 | first_daemon->shortname, | 810 | "Failed to connect peer %s to peer %s with error :\n%s\n", |
776 | second_daemon->shortname, emsg); | 811 | first_daemon->shortname, second_daemon->shortname, emsg); |
777 | } | 812 | } |
778 | #endif | 813 | #endif |
779 | 814 | ||
780 | if (total_connections == expected_connections) | 815 | if (total_connections == expected_connections) |
781 | { | 816 | { |
782 | #if VERBOSE | 817 | #if VERBOSE |
783 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 818 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
784 | "Created %u total connections, which is our target number! Calling send messages.\n", | 819 | "Created %u total connections, which is our target number! Calling send messages.\n", |
785 | total_connections); | 820 | total_connections); |
786 | #endif | 821 | #endif |
787 | 822 | ||
823 | GNUNET_SCHEDULER_cancel (die_task); | ||
824 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
825 | GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); | ||
826 | } | ||
827 | else if (total_connections + failed_connections == expected_connections) | ||
828 | { | ||
829 | if (failed_connections < | ||
830 | (unsigned int) (fail_percentage * total_connections)) | ||
831 | { | ||
788 | GNUNET_SCHEDULER_cancel (die_task); | 832 | GNUNET_SCHEDULER_cancel (die_task); |
789 | die_task = GNUNET_SCHEDULER_NO_TASK; | 833 | die_task = GNUNET_SCHEDULER_NO_TASK; |
790 | GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); | 834 | GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); |
791 | } | 835 | } |
792 | else if (total_connections + failed_connections == expected_connections) | 836 | else |
793 | { | 837 | { |
794 | if (failed_connections < (unsigned int)(fail_percentage * total_connections)) | 838 | GNUNET_SCHEDULER_cancel (die_task); |
795 | { | 839 | die_task = |
796 | GNUNET_SCHEDULER_cancel (die_task); | 840 | GNUNET_SCHEDULER_add_now (&end_badly, |
797 | die_task = GNUNET_SCHEDULER_NO_TASK; | 841 | "from topology_callback (too many failed connections)"); |
798 | GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); | ||
799 | } | ||
800 | else | ||
801 | { | ||
802 | GNUNET_SCHEDULER_cancel (die_task); | ||
803 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); | ||
804 | } | ||
805 | } | 842 | } |
843 | } | ||
806 | else | 844 | else |
807 | { | 845 | { |
808 | #if VERBOSE | 846 | #if VERBOSE |
809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 847 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
810 | "Have %d total connections, %d failed connections, Want %d (at least %d)\n", | 848 | "Have %d total connections, %d failed connections, Want %d (at least %d)\n", |
811 | total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections)); | 849 | total_connections, failed_connections, expected_connections, |
850 | expected_connections - | ||
851 | (unsigned int) (fail_percentage * expected_connections)); | ||
812 | #endif | 852 | #endif |
813 | } | 853 | } |
814 | } | 854 | } |
815 | 855 | ||
816 | static void | 856 | static void |
@@ -818,50 +858,56 @@ connect_topology () | |||
818 | { | 858 | { |
819 | expected_connections = -1; | 859 | expected_connections = -1; |
820 | if ((pg != NULL) && (peers_left == 0)) | 860 | if ((pg != NULL) && (peers_left == 0)) |
821 | { | 861 | { |
822 | expected_connections = GNUNET_TESTING_connect_topology (pg, | 862 | expected_connections = GNUNET_TESTING_connect_topology (pg, |
823 | connection_topology, | 863 | connection_topology, |
824 | connect_topology_option, | 864 | connect_topology_option, |
825 | connect_topology_option_modifier, | 865 | connect_topology_option_modifier, |
826 | TIMEOUT, | 866 | TIMEOUT, |
827 | 12, | 867 | 12, NULL, NULL); |
828 | NULL, NULL); | ||
829 | #if VERBOSE | 868 | #if VERBOSE |
830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
831 | "Have %d expected connections\n", expected_connections); | 870 | "Have %d expected connections\n", expected_connections); |
832 | #endif | 871 | #endif |
833 | } | 872 | } |
834 | 873 | ||
835 | GNUNET_SCHEDULER_cancel (die_task); | 874 | GNUNET_SCHEDULER_cancel (die_task); |
836 | if (expected_connections == GNUNET_SYSERR) | 875 | if (expected_connections == GNUNET_SYSERR) |
837 | { | 876 | { |
838 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); | 877 | die_task = |
839 | } | 878 | GNUNET_SCHEDULER_add_now (&end_badly, |
879 | "from connect topology (bad return)"); | ||
880 | } | ||
840 | 881 | ||
841 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 882 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
842 | &end_badly, "from connect topology (timeout)"); | 883 | &end_badly, |
884 | "from connect topology (timeout)"); | ||
843 | } | 885 | } |
844 | 886 | ||
845 | static void | 887 | static void |
846 | create_topology () | 888 | create_topology () |
847 | { | 889 | { |
848 | peers_left = num_peers; /* Reset counter */ | 890 | peers_left = num_peers; /* Reset counter */ |
849 | if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) | 891 | if (GNUNET_TESTING_create_topology |
850 | { | 892 | (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) |
893 | { | ||
851 | #if VERBOSE | 894 | #if VERBOSE |
852 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 895 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
853 | "Topology set up, now starting peers!\n"); | 896 | "Topology set up, now starting peers!\n"); |
854 | #endif | 897 | #endif |
855 | GNUNET_TESTING_daemons_continue_startup(pg); | 898 | GNUNET_TESTING_daemons_continue_startup (pg); |
856 | } | 899 | } |
857 | else | 900 | else |
858 | { | 901 | { |
859 | GNUNET_SCHEDULER_cancel (die_task); | 902 | GNUNET_SCHEDULER_cancel (die_task); |
860 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)"); | 903 | die_task = |
861 | } | 904 | GNUNET_SCHEDULER_add_now (&end_badly, |
905 | "from create topology (bad return)"); | ||
906 | } | ||
862 | GNUNET_SCHEDULER_cancel (die_task); | 907 | GNUNET_SCHEDULER_cancel (die_task); |
863 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, | 908 | die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, |
864 | &end_badly, "from continue startup (timeout)"); | 909 | &end_badly, |
910 | "from continue startup (timeout)"); | ||
865 | } | 911 | } |
866 | 912 | ||
867 | /** | 913 | /** |
@@ -872,126 +918,134 @@ create_topology () | |||
872 | * @param latency reported latency of the connection with 'other' | 918 | * @param latency reported latency of the connection with 'other' |
873 | * @param distance reported distance (DV) to 'other' | 919 | * @param distance reported distance (DV) to 'other' |
874 | */ | 920 | */ |
875 | static void all_connect_handler (void *cls, | 921 | static void |
876 | const struct | 922 | all_connect_handler (void *cls, |
877 | GNUNET_PeerIdentity * peer, | 923 | const struct |
878 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 924 | GNUNET_PeerIdentity *peer, |
925 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
879 | { | 926 | { |
880 | struct GNUNET_TESTING_Daemon *d = cls; | 927 | struct GNUNET_TESTING_Daemon *d = cls; |
881 | struct GNUNET_TESTING_Daemon *second_daemon; | 928 | struct GNUNET_TESTING_Daemon *second_daemon; |
882 | char *second_shortname; | 929 | char *second_shortname; |
930 | |||
883 | #if !TEST_ALL | 931 | #if !TEST_ALL |
884 | struct TestMessageContext *temp_context; | 932 | struct TestMessageContext *temp_context; |
885 | #endif | 933 | #endif |
886 | uint32_t distance; | 934 | uint32_t distance; |
887 | 935 | ||
888 | if (0 == memcmp(&d->id, peer, sizeof(struct GNUNET_PeerIdentity))) | 936 | if (0 == memcmp (&d->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
889 | return; | 937 | return; |
890 | second_shortname = GNUNET_strdup (GNUNET_i2s(peer)); | 938 | second_shortname = GNUNET_strdup (GNUNET_i2s (peer)); |
891 | distance = get_atsi_distance(atsi); | 939 | distance = get_atsi_distance (atsi); |
892 | 940 | ||
893 | #if VERBOSE | 941 | #if VERBOSE |
894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
895 | "connected peer %s to peer %s, distance %u\n", | 943 | "connected peer %s to peer %s, distance %u\n", |
896 | d->shortname, | 944 | d->shortname, second_shortname, distance); |
897 | second_shortname, | ||
898 | distance); | ||
899 | #endif | 945 | #endif |
900 | 946 | ||
901 | second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey); | 947 | second_daemon = |
948 | GNUNET_CONTAINER_multihashmap_get (peer_daemon_hash, &peer->hashPubKey); | ||
902 | 949 | ||
903 | if (second_daemon == NULL) | 950 | if (second_daemon == NULL) |
904 | { | 951 | { |
905 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 952 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n"); |
906 | "Couldn't find second peer!\n"); | 953 | GNUNET_free (second_shortname); |
907 | GNUNET_free(second_shortname); | 954 | return; |
908 | return; | 955 | } |
909 | } | ||
910 | #if !TEST_ALL | 956 | #if !TEST_ALL |
911 | if (distance > 1) | 957 | if (distance > 1) |
912 | { | 958 | { |
913 | temp_total_other_messages++; | 959 | temp_total_other_messages++; |
914 | temp_context = GNUNET_malloc(sizeof(struct TestMessageContext)); | 960 | temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); |
915 | temp_context->peer1 = d; | 961 | temp_context->peer1 = d; |
916 | temp_context->peer2 = second_daemon; | 962 | temp_context->peer2 = second_daemon; |
917 | temp_context->next = other_test_messages; | 963 | temp_context->next = other_test_messages; |
918 | temp_context->uid = total_connections + temp_total_other_messages; | 964 | temp_context->uid = total_connections + temp_total_other_messages; |
919 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 965 | temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
920 | other_test_messages = temp_context; | 966 | other_test_messages = temp_context; |
921 | } | 967 | } |
922 | #endif | 968 | #endif |
923 | 969 | ||
924 | if (dotOutFile != NULL) | 970 | if (dotOutFile != NULL) |
925 | { | 971 | { |
926 | if (distance == 1) | 972 | if (distance == 1) |
927 | fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname); | 973 | fprintf (dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname); |
928 | else if (distance == 2) | 974 | else if (distance == 2) |
929 | fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname); | 975 | fprintf (dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, |
930 | else if (distance == 3) | 976 | second_shortname); |
931 | fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname); | 977 | else if (distance == 3) |
932 | else if (distance == 4) | 978 | fprintf (dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, |
933 | fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname); | 979 | second_shortname); |
934 | else | 980 | else if (distance == 4) |
935 | fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, second_shortname); | 981 | fprintf (dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, |
936 | } | 982 | second_shortname); |
937 | GNUNET_free(second_shortname); | 983 | else |
984 | fprintf (dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, | ||
985 | second_shortname); | ||
986 | } | ||
987 | GNUNET_free (second_shortname); | ||
938 | 988 | ||
939 | if (temp_total_other_messages == num_additional_messages) | 989 | if (temp_total_other_messages == num_additional_messages) |
940 | { | 990 | { |
941 | GNUNET_SCHEDULER_add_now (&send_other_messages, NULL); | 991 | GNUNET_SCHEDULER_add_now (&send_other_messages, NULL); |
942 | } | 992 | } |
943 | } | 993 | } |
944 | 994 | ||
945 | static void | 995 | static void |
946 | peers_started_callback (void *cls, | 996 | peers_started_callback (void *cls, |
947 | const struct GNUNET_PeerIdentity *id, | 997 | const struct GNUNET_PeerIdentity *id, |
948 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 998 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
949 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 999 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
950 | { | 1000 | { |
951 | struct PeerContext *new_peer; | 1001 | struct PeerContext *new_peer; |
1002 | |||
952 | if (emsg != NULL) | 1003 | if (emsg != NULL) |
953 | { | 1004 | { |
954 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", | 1005 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
955 | emsg); | 1006 | "Failed to start daemon with error: `%s'\n", emsg); |
956 | return; | 1007 | return; |
957 | } | 1008 | } |
958 | GNUNET_assert (id != NULL); | 1009 | GNUNET_assert (id != NULL); |
959 | #if VERBOSE | 1010 | #if VERBOSE |
960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", | 1011 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", |
961 | (num_peers - peers_left) + 1, num_peers); | 1012 | (num_peers - peers_left) + 1, num_peers); |
962 | #endif | 1013 | #endif |
963 | GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1014 | GNUNET_assert (GNUNET_SYSERR != |
964 | 1015 | GNUNET_CONTAINER_multihashmap_put (peer_daemon_hash, | |
965 | new_peer = GNUNET_malloc(sizeof(struct PeerContext)); | 1016 | &id->hashPubKey, d, |
966 | new_peer->peer_handle = GNUNET_CORE_connect(cfg, | 1017 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
967 | 1, | 1018 | |
968 | d, NULL, | 1019 | new_peer = GNUNET_malloc (sizeof (struct PeerContext)); |
969 | &all_connect_handler, | 1020 | new_peer->peer_handle = GNUNET_CORE_connect (cfg, |
970 | NULL, NULL, NULL, | 1021 | 1, |
971 | GNUNET_NO, NULL, GNUNET_NO, | 1022 | d, NULL, |
972 | no_handlers); | 1023 | &all_connect_handler, |
1024 | NULL, NULL, NULL, | ||
1025 | GNUNET_NO, NULL, GNUNET_NO, | ||
1026 | no_handlers); | ||
973 | new_peer->daemon = d; | 1027 | new_peer->daemon = d; |
974 | new_peer->next = all_peers; | 1028 | new_peer->next = all_peers; |
975 | all_peers = new_peer; | 1029 | all_peers = new_peer; |
976 | peers_left--; | 1030 | peers_left--; |
977 | 1031 | ||
978 | if (peers_left == 0) | 1032 | if (peers_left == 0) |
979 | { | 1033 | { |
980 | #if VERBOSE | 1034 | #if VERBOSE |
981 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
982 | "All %d daemons started, now creating topology!\n", | 1036 | "All %d daemons started, now creating topology!\n", num_peers); |
983 | num_peers); | ||
984 | #endif | 1037 | #endif |
985 | GNUNET_SCHEDULER_cancel (die_task); | 1038 | GNUNET_SCHEDULER_cancel (die_task); |
986 | /* Set up task in case topology creation doesn't finish | 1039 | /* Set up task in case topology creation doesn't finish |
987 | * within a reasonable amount of time */ | 1040 | * within a reasonable amount of time */ |
988 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 1041 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
989 | (GNUNET_TIME_UNIT_MINUTES, 5), | 1042 | (GNUNET_TIME_UNIT_MINUTES, 5), |
990 | &end_badly, "from peers_started_callback"); | 1043 | &end_badly, |
991 | 1044 | "from peers_started_callback"); | |
992 | connect_topology (); | 1045 | |
993 | ok = 0; | 1046 | connect_topology (); |
994 | } | 1047 | ok = 0; |
1048 | } | ||
995 | } | 1049 | } |
996 | 1050 | ||
997 | /** | 1051 | /** |
@@ -1004,37 +1058,36 @@ peers_started_callback (void *cls, | |||
1004 | */ | 1058 | */ |
1005 | static void | 1059 | static void |
1006 | hostkey_callback (void *cls, | 1060 | hostkey_callback (void *cls, |
1007 | const struct GNUNET_PeerIdentity *id, | 1061 | const struct GNUNET_PeerIdentity *id, |
1008 | struct GNUNET_TESTING_Daemon *d, | 1062 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
1009 | const char *emsg) | ||
1010 | { | 1063 | { |
1011 | if (emsg != NULL) | 1064 | if (emsg != NULL) |
1012 | { | 1065 | { |
1013 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg); | 1066 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1014 | } | 1067 | "Hostkey callback received error: %s\n", emsg); |
1068 | } | ||
1015 | 1069 | ||
1016 | #if VERBOSE | 1070 | #if VERBOSE |
1017 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1071 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1018 | "Hostkey created for peer `%s'\n", | 1072 | "Hostkey created for peer `%s'\n", GNUNET_i2s (id)); |
1019 | GNUNET_i2s(id)); | ||
1020 | #endif | 1073 | #endif |
1021 | peers_left--; | 1074 | peers_left--; |
1022 | if (peers_left == 0) | 1075 | if (peers_left == 0) |
1023 | { | 1076 | { |
1024 | #if VERBOSE | 1077 | #if VERBOSE |
1025 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1026 | "All %d hostkeys created, now creating topology!\n", | 1079 | "All %d hostkeys created, now creating topology!\n", num_peers); |
1027 | num_peers); | ||
1028 | #endif | 1080 | #endif |
1029 | GNUNET_SCHEDULER_cancel (die_task); | 1081 | GNUNET_SCHEDULER_cancel (die_task); |
1030 | /* Set up task in case topology creation doesn't finish | 1082 | /* Set up task in case topology creation doesn't finish |
1031 | * within a reasonable amount of time */ | 1083 | * within a reasonable amount of time */ |
1032 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 1084 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
1033 | (GNUNET_TIME_UNIT_MINUTES, 5), | 1085 | (GNUNET_TIME_UNIT_MINUTES, 5), |
1034 | &end_badly, "from hostkey_callback"); | 1086 | &end_badly, |
1035 | GNUNET_SCHEDULER_add_now(&create_topology, NULL); | 1087 | "from hostkey_callback"); |
1036 | ok = 0; | 1088 | GNUNET_SCHEDULER_add_now (&create_topology, NULL); |
1037 | } | 1089 | ok = 0; |
1090 | } | ||
1038 | } | 1091 | } |
1039 | 1092 | ||
1040 | static void | 1093 | static void |
@@ -1042,117 +1095,141 @@ run (void *cls, | |||
1042 | char *const *args, | 1095 | char *const *args, |
1043 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 1096 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
1044 | { | 1097 | { |
1045 | char * topology_str; | 1098 | char *topology_str; |
1046 | char * connect_topology_str; | 1099 | char *connect_topology_str; |
1047 | char * blacklist_topology_str; | 1100 | char *blacklist_topology_str; |
1048 | char * connect_topology_option_str; | 1101 | char *connect_topology_option_str; |
1049 | char * connect_topology_option_modifier_string; | 1102 | char *connect_topology_option_modifier_string; |
1103 | |||
1050 | ok = 1; | 1104 | ok = 1; |
1051 | 1105 | ||
1052 | dotOutFile = fopen (dotOutFileName, "w"); | 1106 | dotOutFile = fopen (dotOutFileName, "w"); |
1053 | if (dotOutFile != NULL) | 1107 | if (dotOutFile != NULL) |
1054 | { | 1108 | { |
1055 | fprintf (dotOutFile, "strict graph G {\n"); | 1109 | fprintf (dotOutFile, "strict graph G {\n"); |
1056 | } | 1110 | } |
1057 | 1111 | ||
1058 | #if VERBOSE | 1112 | #if VERBOSE |
1059 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1060 | "Starting daemons based on config file %s\n", cfgfile); | 1114 | "Starting daemons based on config file %s\n", cfgfile); |
1061 | #endif | 1115 | #endif |
1062 | 1116 | ||
1063 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) | 1117 | if (GNUNET_YES != |
1064 | { | 1118 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", |
1065 | ok = 404; | 1119 | &test_directory)) |
1066 | return; | 1120 | { |
1067 | } | 1121 | ok = 404; |
1122 | return; | ||
1123 | } | ||
1068 | 1124 | ||
1069 | if ((GNUNET_YES == | 1125 | if ((GNUNET_YES == |
1070 | GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology", | 1126 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology", |
1071 | &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str))) | 1127 | &topology_str)) && |
1072 | { | 1128 | (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) |
1073 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1129 | { |
1074 | "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY"); | 1130 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1075 | topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ | 1131 | "Invalid topology `%s' given for section %s option %s\n", |
1076 | } | 1132 | topology_str, "TESTING", "TOPOLOGY"); |
1133 | topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ | ||
1134 | } | ||
1077 | 1135 | ||
1078 | if ((GNUNET_YES == | 1136 | if ((GNUNET_YES == |
1079 | GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology", | 1137 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
1080 | &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str))) | 1138 | "connect_topology", |
1081 | { | 1139 | &connect_topology_str)) && |
1082 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1140 | (GNUNET_NO == |
1083 | "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); | 1141 | GNUNET_TESTING_topology_get (&connection_topology, |
1084 | } | 1142 | connect_topology_str))) |
1085 | GNUNET_free_non_null(connect_topology_str); | 1143 | { |
1144 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1145 | "Invalid connect topology `%s' given for section %s option %s\n", | ||
1146 | connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); | ||
1147 | } | ||
1148 | GNUNET_free_non_null (connect_topology_str); | ||
1086 | if ((GNUNET_YES == | 1149 | if ((GNUNET_YES == |
1087 | GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option", | 1150 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
1088 | &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str))) | 1151 | "connect_topology_option", |
1089 | { | 1152 | &connect_topology_option_str)) && |
1090 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1153 | (GNUNET_NO == |
1091 | "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION"); | 1154 | GNUNET_TESTING_topology_option_get (&connect_topology_option, |
1092 | connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ | 1155 | connect_topology_option_str))) |
1093 | } | 1156 | { |
1094 | GNUNET_free_non_null(connect_topology_option_str); | 1157 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1158 | "Invalid connect topology option `%s' given for section %s option %s\n", | ||
1159 | connect_topology_option_str, "TESTING", | ||
1160 | "CONNECT_TOPOLOGY_OPTION"); | ||
1161 | connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ | ||
1162 | } | ||
1163 | GNUNET_free_non_null (connect_topology_option_str); | ||
1095 | if (GNUNET_YES == | 1164 | if (GNUNET_YES == |
1096 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier", | 1165 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
1097 | &connect_topology_option_modifier_string)) | 1166 | "connect_topology_option_modifier", |
1167 | &connect_topology_option_modifier_string)) | ||
1168 | { | ||
1169 | if (sscanf | ||
1170 | (connect_topology_option_modifier_string, "%lf", | ||
1171 | &connect_topology_option_modifier) != 1) | ||
1098 | { | 1172 | { |
1099 | if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1) | 1173 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1100 | { | 1174 | _ |
1101 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1175 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1102 | _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1176 | connect_topology_option_modifier_string, |
1103 | connect_topology_option_modifier_string, | 1177 | "connect_topology_option_modifier", "TESTING"); |
1104 | "connect_topology_option_modifier", | ||
1105 | "TESTING"); | ||
1106 | } | ||
1107 | GNUNET_free (connect_topology_option_modifier_string); | ||
1108 | } | 1178 | } |
1179 | GNUNET_free (connect_topology_option_modifier_string); | ||
1180 | } | ||
1109 | 1181 | ||
1110 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports", | 1182 | if (GNUNET_YES != |
1111 | &blacklist_transports)) | 1183 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
1184 | "blacklist_transports", | ||
1185 | &blacklist_transports)) | ||
1112 | blacklist_transports = NULL; | 1186 | blacklist_transports = NULL; |
1113 | 1187 | ||
1114 | if ((GNUNET_YES == | 1188 | if ((GNUNET_YES == |
1115 | GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology", | 1189 | GNUNET_CONFIGURATION_get_value_string (cfg, "testing", |
1116 | &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str))) | 1190 | "blacklist_topology", |
1117 | { | 1191 | &blacklist_topology_str)) && |
1118 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1192 | (GNUNET_NO == |
1119 | "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); | 1193 | GNUNET_TESTING_topology_get (&blacklist_topology, |
1120 | } | 1194 | blacklist_topology_str))) |
1121 | GNUNET_free_non_null(topology_str); | 1195 | { |
1122 | GNUNET_free_non_null(blacklist_topology_str); | 1196 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1197 | "Invalid topology `%s' given for section %s option %s\n", | ||
1198 | topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); | ||
1199 | } | ||
1200 | GNUNET_free_non_null (topology_str); | ||
1201 | GNUNET_free_non_null (blacklist_topology_str); | ||
1123 | if (GNUNET_SYSERR == | 1202 | if (GNUNET_SYSERR == |
1124 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", | 1203 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", |
1125 | &num_peers)) | 1204 | &num_peers)) |
1126 | num_peers = DEFAULT_NUM_PEERS; | 1205 | num_peers = DEFAULT_NUM_PEERS; |
1127 | 1206 | ||
1128 | if (GNUNET_SYSERR == | 1207 | if (GNUNET_SYSERR == |
1129 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "additional_messages", | 1208 | GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
1209 | "additional_messages", | ||
1130 | &num_additional_messages)) | 1210 | &num_additional_messages)) |
1131 | num_additional_messages = DEFAULT_ADDITIONAL_MESSAGES; | 1211 | num_additional_messages = DEFAULT_ADDITIONAL_MESSAGES; |
1132 | 1212 | ||
1133 | main_cfg = cfg; | 1213 | main_cfg = cfg; |
1134 | 1214 | ||
1135 | GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); | 1215 | GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); |
1136 | peers_left = num_peers; | 1216 | peers_left = num_peers; |
1137 | 1217 | ||
1138 | /* Set up a task to end testing if peer start fails */ | 1218 | /* Set up a task to end testing if peer start fails */ |
1139 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 1219 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
1140 | (GNUNET_TIME_UNIT_MINUTES, 5), | 1220 | (GNUNET_TIME_UNIT_MINUTES, 5), |
1141 | &end_badly, "didn't start all daemons in reasonable amount of time!!!"); | 1221 | &end_badly, |
1222 | "didn't start all daemons in reasonable amount of time!!!"); | ||
1142 | 1223 | ||
1143 | peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left); | 1224 | peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create (peers_left); |
1144 | pg = GNUNET_TESTING_daemons_start (cfg, | 1225 | pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ |
1145 | peers_left, /* Total number of peers */ | 1226 | peers_left, /* Number of outstanding connections */ |
1146 | peers_left, /* Number of outstanding connections */ | 1227 | peers_left, /* Number of parallel ssh connections, or peers being started at once */ |
1147 | peers_left, /* Number of parallel ssh connections, or peers being started at once */ | ||
1148 | TIMEOUT, | 1228 | TIMEOUT, |
1149 | &hostkey_callback, | 1229 | &hostkey_callback, |
1150 | NULL, | 1230 | NULL, |
1151 | &peers_started_callback, | 1231 | &peers_started_callback, |
1152 | NULL, | 1232 | NULL, &topology_callback, NULL, NULL); |
1153 | &topology_callback, | ||
1154 | NULL, | ||
1155 | NULL); | ||
1156 | 1233 | ||
1157 | } | 1234 | } |
1158 | 1235 | ||
@@ -1160,7 +1237,8 @@ static int | |||
1160 | check () | 1237 | check () |
1161 | { | 1238 | { |
1162 | int ret; | 1239 | int ret; |
1163 | char *const argv[] = {"test-transport-dv", | 1240 | |
1241 | char *const argv[] = { "test-transport-dv", | ||
1164 | "-c", | 1242 | "-c", |
1165 | "test_transport_dv_data.conf", | 1243 | "test_transport_dv_data.conf", |
1166 | #if VERBOSE | 1244 | #if VERBOSE |
@@ -1172,12 +1250,13 @@ check () | |||
1172 | GNUNET_GETOPT_OPTION_END | 1250 | GNUNET_GETOPT_OPTION_END |
1173 | }; | 1251 | }; |
1174 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 1252 | ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
1175 | argv, "test-transport-dv", "nohelp", | 1253 | argv, "test-transport-dv", "nohelp", |
1176 | options, &run, &ok); | 1254 | options, &run, &ok); |
1177 | if (ret != GNUNET_OK) | 1255 | if (ret != GNUNET_OK) |
1178 | { | 1256 | { |
1179 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-transport-dv': Failed with error code %d\n", ret); | 1257 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1180 | } | 1258 | "`test-transport-dv': Failed with error code %d\n", ret); |
1259 | } | ||
1181 | return ok; | 1260 | return ok; |
1182 | } | 1261 | } |
1183 | 1262 | ||
@@ -1199,9 +1278,10 @@ main (int argc, char *argv[]) | |||
1199 | * of by the testing framework. | 1278 | * of by the testing framework. |
1200 | */ | 1279 | */ |
1201 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) | 1280 | if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) |
1202 | { | 1281 | { |
1203 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); | 1282 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1204 | } | 1283 | "Failed to remove testing directory %s\n", test_directory); |
1284 | } | ||
1205 | return ret; | 1285 | return ret; |
1206 | } | 1286 | } |
1207 | 1287 | ||