diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_peer.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_peer.c | 1201 |
1 files changed, 605 insertions, 596 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index 23eb6b225..52a0c2bd3 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c | |||
@@ -46,18 +46,20 @@ | |||
46 | #include "gnunet-service-cadet_tunnels.h" | 46 | #include "gnunet-service-cadet_tunnels.h" |
47 | 47 | ||
48 | 48 | ||
49 | #define LOG(level, ...) GNUNET_log_from(level, "cadet-per", __VA_ARGS__) | 49 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-per", __VA_ARGS__) |
50 | 50 | ||
51 | 51 | ||
52 | /** | 52 | /** |
53 | * How long do we wait until tearing down an idle peer? | 53 | * How long do we wait until tearing down an idle peer? |
54 | */ | 54 | */ |
55 | #define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) | 55 | #define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply ( \ |
56 | GNUNET_TIME_UNIT_MINUTES, 5) | ||
56 | 57 | ||
57 | /** | 58 | /** |
58 | * How long do we keep paths around if we no longer care about the peer? | 59 | * How long do we keep paths around if we no longer care about the peer? |
59 | */ | 60 | */ |
60 | #define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) | 61 | #define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply ( \ |
62 | GNUNET_TIME_UNIT_MINUTES, 2) | ||
61 | 63 | ||
62 | /** | 64 | /** |
63 | * Queue size when we start dropping OOO messages. | 65 | * Queue size when we start dropping OOO messages. |
@@ -69,7 +71,8 @@ | |||
69 | * Data structure used to track whom we have to notify about changes | 71 | * Data structure used to track whom we have to notify about changes |
70 | * to our message queue. | 72 | * to our message queue. |
71 | */ | 73 | */ |
72 | struct GCP_MessageQueueManager { | 74 | struct GCP_MessageQueueManager |
75 | { | ||
73 | /** | 76 | /** |
74 | * Kept in a DLL. | 77 | * Kept in a DLL. |
75 | */ | 78 | */ |
@@ -105,7 +108,8 @@ struct GCP_MessageQueueManager { | |||
105 | /** | 108 | /** |
106 | * Struct containing all information regarding a given peer | 109 | * Struct containing all information regarding a given peer |
107 | */ | 110 | */ |
108 | struct CadetPeer { | 111 | struct CadetPeer |
112 | { | ||
109 | /** | 113 | /** |
110 | * ID of the peer | 114 | * ID of the peer |
111 | */ | 115 | */ |
@@ -235,23 +239,23 @@ struct CadetPeer { | |||
235 | * @return Static string for it's ID. | 239 | * @return Static string for it's ID. |
236 | */ | 240 | */ |
237 | const char * | 241 | const char * |
238 | GCP_2s(const struct CadetPeer *cp) | 242 | GCP_2s (const struct CadetPeer *cp) |
239 | { | 243 | { |
240 | static char buf[5]; | 244 | static char buf[5]; |
241 | char *ret; | 245 | char *ret; |
242 | 246 | ||
243 | if ((NULL == cp) || | 247 | if ((NULL == cp) || |
244 | (0 == GNUNET_is_zero(&cp->pid.public_key))) | 248 | (0 == GNUNET_is_zero (&cp->pid.public_key))) |
245 | return "NULL"; | 249 | return "NULL"; |
246 | 250 | ||
247 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string(&cp->pid.public_key); | 251 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&cp->pid.public_key); |
248 | if (NULL == ret) | 252 | if (NULL == ret) |
249 | return "NULL"; | 253 | return "NULL"; |
250 | 254 | ||
251 | GNUNET_strlcpy(buf, | 255 | GNUNET_strlcpy (buf, |
252 | ret, | 256 | ret, |
253 | sizeof(buf)); | 257 | sizeof(buf)); |
254 | GNUNET_free(ret); | 258 | GNUNET_free (ret); |
255 | return buf; | 259 | return buf; |
256 | } | 260 | } |
257 | 261 | ||
@@ -272,8 +276,8 @@ GCP_2s(const struct CadetPeer *cp) | |||
272 | * positive scores mean path is more desirable | 276 | * positive scores mean path is more desirable |
273 | */ | 277 | */ |
274 | double | 278 | double |
275 | GCP_get_desirability_of_path(struct CadetPeer *cp, | 279 | GCP_get_desirability_of_path (struct CadetPeer *cp, |
276 | unsigned int off) | 280 | unsigned int off) |
277 | { | 281 | { |
278 | unsigned int num_alts = cp->num_paths; | 282 | unsigned int num_alts = cp->num_paths; |
279 | unsigned int off_sum; | 283 | unsigned int off_sum; |
@@ -281,8 +285,8 @@ GCP_get_desirability_of_path(struct CadetPeer *cp, | |||
281 | double path_delta; | 285 | double path_delta; |
282 | double weight_alts; | 286 | double weight_alts; |
283 | 287 | ||
284 | GNUNET_assert(num_alts >= 1); /* 'path' should be in there! */ | 288 | GNUNET_assert (num_alts >= 1); /* 'path' should be in there! */ |
285 | GNUNET_assert(0 != cp->path_dll_length); | 289 | GNUNET_assert (0 != cp->path_dll_length); |
286 | 290 | ||
287 | /* We maintain 'off_sum' in 'peer' and thereby | 291 | /* We maintain 'off_sum' in 'peer' and thereby |
288 | avoid the SLOW recalculation each time. Kept here | 292 | avoid the SLOW recalculation each time. Kept here |
@@ -294,7 +298,7 @@ GCP_get_desirability_of_path(struct CadetPeer *cp, | |||
294 | NULL != pe; | 298 | NULL != pe; |
295 | pe = pe->next) | 299 | pe = pe->next) |
296 | off_sum += j; | 300 | off_sum += j; |
297 | GNUNET_assert(off_sum == cp->off_sum); | 301 | GNUNET_assert (off_sum == cp->off_sum); |
298 | #else | 302 | #else |
299 | off_sum = cp->off_sum; | 303 | off_sum = cp->off_sum; |
300 | #endif | 304 | #endif |
@@ -323,63 +327,63 @@ GCP_get_desirability_of_path(struct CadetPeer *cp, | |||
323 | * @param cls peer to clean up | 327 | * @param cls peer to clean up |
324 | */ | 328 | */ |
325 | static void | 329 | static void |
326 | destroy_peer(void *cls) | 330 | destroy_peer (void *cls) |
327 | { | 331 | { |
328 | struct CadetPeer *cp = cls; | 332 | struct CadetPeer *cp = cls; |
329 | 333 | ||
330 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 334 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
331 | "Destroying state about peer %s\n", | 335 | "Destroying state about peer %s\n", |
332 | GCP_2s(cp)); | 336 | GCP_2s (cp)); |
333 | cp->destroy_task = NULL; | 337 | cp->destroy_task = NULL; |
334 | GNUNET_assert(NULL == cp->t); | 338 | GNUNET_assert (NULL == cp->t); |
335 | GNUNET_assert(NULL == cp->core_mq); | 339 | GNUNET_assert (NULL == cp->core_mq); |
336 | GNUNET_assert(0 == cp->num_paths); | 340 | GNUNET_assert (0 == cp->num_paths); |
337 | for (unsigned int i = 0; i < cp->path_dll_length; i++) | 341 | for (unsigned int i = 0; i < cp->path_dll_length; i++) |
338 | GNUNET_assert(NULL == cp->path_heads[i]); | 342 | GNUNET_assert (NULL == cp->path_heads[i]); |
339 | GNUNET_assert(0 == GNUNET_CONTAINER_multishortmap_size(cp->connections)); | 343 | GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (cp->connections)); |
340 | GNUNET_assert(GNUNET_YES == | 344 | GNUNET_assert (GNUNET_YES == |
341 | GNUNET_CONTAINER_multipeermap_remove(peers, | 345 | GNUNET_CONTAINER_multipeermap_remove (peers, |
342 | &cp->pid, | 346 | &cp->pid, |
343 | cp)); | 347 | cp)); |
344 | GNUNET_free_non_null(cp->path_heads); | 348 | GNUNET_free_non_null (cp->path_heads); |
345 | GNUNET_free_non_null(cp->path_tails); | 349 | GNUNET_free_non_null (cp->path_tails); |
346 | cp->path_dll_length = 0; | 350 | cp->path_dll_length = 0; |
347 | if (NULL != cp->search_h) | 351 | if (NULL != cp->search_h) |
348 | { | 352 | { |
349 | GCD_search_stop(cp->search_h); | 353 | GCD_search_stop (cp->search_h); |
350 | cp->search_h = NULL; | 354 | cp->search_h = NULL; |
351 | } | 355 | } |
352 | /* FIXME: clean up search_delayedXXX! */ | 356 | /* FIXME: clean up search_delayedXXX! */ |
353 | 357 | ||
354 | if (NULL != cp->hello_offer) | 358 | if (NULL != cp->hello_offer) |
355 | { | 359 | { |
356 | GNUNET_TRANSPORT_offer_hello_cancel(cp->hello_offer); | 360 | GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer); |
357 | cp->hello_offer = NULL; | 361 | cp->hello_offer = NULL; |
358 | } | 362 | } |
359 | if (NULL != cp->connectivity_suggestion) | 363 | if (NULL != cp->connectivity_suggestion) |
360 | { | 364 | { |
361 | GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion); | 365 | GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion); |
362 | cp->connectivity_suggestion = NULL; | 366 | cp->connectivity_suggestion = NULL; |
363 | } | 367 | } |
364 | GNUNET_CONTAINER_multishortmap_destroy(cp->connections); | 368 | GNUNET_CONTAINER_multishortmap_destroy (cp->connections); |
365 | if (NULL != cp->path_heap) | 369 | if (NULL != cp->path_heap) |
366 | { | 370 | { |
367 | GNUNET_CONTAINER_heap_destroy(cp->path_heap); | 371 | GNUNET_CONTAINER_heap_destroy (cp->path_heap); |
368 | cp->path_heap = NULL; | 372 | cp->path_heap = NULL; |
369 | } | 373 | } |
370 | if (NULL != cp->heap_cleanup_task) | 374 | if (NULL != cp->heap_cleanup_task) |
371 | { | 375 | { |
372 | GNUNET_SCHEDULER_cancel(cp->heap_cleanup_task); | 376 | GNUNET_SCHEDULER_cancel (cp->heap_cleanup_task); |
373 | cp->heap_cleanup_task = NULL; | 377 | cp->heap_cleanup_task = NULL; |
374 | } | 378 | } |
375 | GNUNET_free_non_null(cp->hello); | 379 | GNUNET_free_non_null (cp->hello); |
376 | /* Peer should not be freed if paths exist; if there are no paths, | 380 | /* Peer should not be freed if paths exist; if there are no paths, |
377 | there ought to be no connections, and without connections, no | 381 | there ought to be no connections, and without connections, no |
378 | notifications. Thus we can assert that mqm_head is empty at this | 382 | notifications. Thus we can assert that mqm_head is empty at this |
379 | point. */ | 383 | point. */ |
380 | GNUNET_assert(NULL == cp->mqm_head); | 384 | GNUNET_assert (NULL == cp->mqm_head); |
381 | GNUNET_assert(NULL == cp->mqm_ready_ptr); | 385 | GNUNET_assert (NULL == cp->mqm_ready_ptr); |
382 | GNUNET_free(cp); | 386 | GNUNET_free (cp); |
383 | } | 387 | } |
384 | 388 | ||
385 | 389 | ||
@@ -389,64 +393,64 @@ destroy_peer(void *cls) | |||
389 | * @param cp the more-active peer | 393 | * @param cp the more-active peer |
390 | */ | 394 | */ |
391 | static void | 395 | static void |
392 | consider_peer_activate(struct CadetPeer *cp) | 396 | consider_peer_activate (struct CadetPeer *cp) |
393 | { | 397 | { |
394 | uint32_t strength; | 398 | uint32_t strength; |
395 | 399 | ||
396 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 400 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
397 | "Updating peer %s activation state (%u connections)%s%s\n", | 401 | "Updating peer %s activation state (%u connections)%s%s\n", |
398 | GCP_2s(cp), | 402 | GCP_2s (cp), |
399 | GNUNET_CONTAINER_multishortmap_size(cp->connections), | 403 | GNUNET_CONTAINER_multishortmap_size (cp->connections), |
400 | (NULL == cp->t) ? "" : " with tunnel", | 404 | (NULL == cp->t) ? "" : " with tunnel", |
401 | (NULL == cp->core_mq) ? "" : " with CORE link"); | 405 | (NULL == cp->core_mq) ? "" : " with CORE link"); |
402 | if (NULL != cp->destroy_task) | 406 | if (NULL != cp->destroy_task) |
403 | { | 407 | { |
404 | /* It's active, do not destory! */ | 408 | /* It's active, do not destory! */ |
405 | GNUNET_SCHEDULER_cancel(cp->destroy_task); | 409 | GNUNET_SCHEDULER_cancel (cp->destroy_task); |
406 | cp->destroy_task = NULL; | 410 | cp->destroy_task = NULL; |
407 | } | 411 | } |
408 | if ((0 == GNUNET_CONTAINER_multishortmap_size(cp->connections)) && | 412 | if ((0 == GNUNET_CONTAINER_multishortmap_size (cp->connections)) && |
409 | (NULL == cp->t)) | 413 | (NULL == cp->t)) |
414 | { | ||
415 | /* We're just on a path or directly connected; don't bother too much */ | ||
416 | if (NULL != cp->connectivity_suggestion) | ||
410 | { | 417 | { |
411 | /* We're just on a path or directly connected; don't bother too much */ | 418 | GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion); |
412 | if (NULL != cp->connectivity_suggestion) | 419 | cp->connectivity_suggestion = NULL; |
413 | { | ||
414 | GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion); | ||
415 | cp->connectivity_suggestion = NULL; | ||
416 | } | ||
417 | if (NULL != cp->search_h) | ||
418 | { | ||
419 | GCD_search_stop(cp->search_h); | ||
420 | cp->search_h = NULL; | ||
421 | } | ||
422 | return; | ||
423 | } | 420 | } |
424 | if (NULL == cp->core_mq) | 421 | if (NULL != cp->search_h) |
425 | { | 422 | { |
426 | /* Lacks direct connection, try to create one by querying the DHT */ | 423 | GCD_search_stop (cp->search_h); |
427 | if ((NULL == cp->search_h) && | 424 | cp->search_h = NULL; |
428 | (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths)) | ||
429 | cp->search_h | ||
430 | = GCD_search(&cp->pid); | ||
431 | } | 425 | } |
426 | return; | ||
427 | } | ||
428 | if (NULL == cp->core_mq) | ||
429 | { | ||
430 | /* Lacks direct connection, try to create one by querying the DHT */ | ||
431 | if ((NULL == cp->search_h) && | ||
432 | (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths)) | ||
433 | cp->search_h | ||
434 | = GCD_search (&cp->pid); | ||
435 | } | ||
432 | else | 436 | else |
437 | { | ||
438 | /* Have direct connection, stop DHT search if active */ | ||
439 | if (NULL != cp->search_h) | ||
433 | { | 440 | { |
434 | /* Have direct connection, stop DHT search if active */ | 441 | GCD_search_stop (cp->search_h); |
435 | if (NULL != cp->search_h) | 442 | cp->search_h = NULL; |
436 | { | ||
437 | GCD_search_stop(cp->search_h); | ||
438 | cp->search_h = NULL; | ||
439 | } | ||
440 | } | 443 | } |
444 | } | ||
441 | 445 | ||
442 | /* If we have a tunnel, our urge for connections is much bigger */ | 446 | /* If we have a tunnel, our urge for connections is much bigger */ |
443 | strength = (NULL != cp->t) ? 32 : 1; | 447 | strength = (NULL != cp->t) ? 32 : 1; |
444 | if (NULL != cp->connectivity_suggestion) | 448 | if (NULL != cp->connectivity_suggestion) |
445 | GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion); | 449 | GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion); |
446 | cp->connectivity_suggestion | 450 | cp->connectivity_suggestion |
447 | = GNUNET_ATS_connectivity_suggest(ats_ch, | 451 | = GNUNET_ATS_connectivity_suggest (ats_ch, |
448 | &cp->pid, | 452 | &cp->pid, |
449 | strength); | 453 | strength); |
450 | } | 454 | } |
451 | 455 | ||
452 | 456 | ||
@@ -456,7 +460,7 @@ consider_peer_activate(struct CadetPeer *cp) | |||
456 | * @param cp peer to clean up | 460 | * @param cp peer to clean up |
457 | */ | 461 | */ |
458 | static void | 462 | static void |
459 | consider_peer_destroy(struct CadetPeer *cp); | 463 | consider_peer_destroy (struct CadetPeer *cp); |
460 | 464 | ||
461 | 465 | ||
462 | /** | 466 | /** |
@@ -466,15 +470,15 @@ consider_peer_destroy(struct CadetPeer *cp); | |||
466 | * @param cls a `struct CadetPeer`. | 470 | * @param cls a `struct CadetPeer`. |
467 | */ | 471 | */ |
468 | static void | 472 | static void |
469 | drop_paths(void *cls) | 473 | drop_paths (void *cls) |
470 | { | 474 | { |
471 | struct CadetPeer *cp = cls; | 475 | struct CadetPeer *cp = cls; |
472 | struct CadetPeerPath *path; | 476 | struct CadetPeerPath *path; |
473 | 477 | ||
474 | cp->destroy_task = NULL; | 478 | cp->destroy_task = NULL; |
475 | while (NULL != (path = GNUNET_CONTAINER_heap_remove_root(cp->path_heap))) | 479 | while (NULL != (path = GNUNET_CONTAINER_heap_remove_root (cp->path_heap))) |
476 | GCPP_release(path); | 480 | GCPP_release (path); |
477 | consider_peer_destroy(cp); | 481 | consider_peer_destroy (cp); |
478 | } | 482 | } |
479 | 483 | ||
480 | 484 | ||
@@ -484,43 +488,44 @@ drop_paths(void *cls) | |||
484 | * @param cp peer to clean up | 488 | * @param cp peer to clean up |
485 | */ | 489 | */ |
486 | static void | 490 | static void |
487 | consider_peer_destroy(struct CadetPeer *cp) | 491 | consider_peer_destroy (struct CadetPeer *cp) |
488 | { | 492 | { |
489 | struct GNUNET_TIME_Relative exp; | 493 | struct GNUNET_TIME_Relative exp; |
490 | 494 | ||
491 | if (NULL != cp->destroy_task) | 495 | if (NULL != cp->destroy_task) |
492 | { | 496 | { |
493 | GNUNET_SCHEDULER_cancel(cp->destroy_task); | 497 | GNUNET_SCHEDULER_cancel (cp->destroy_task); |
494 | cp->destroy_task = NULL; | 498 | cp->destroy_task = NULL; |
495 | } | 499 | } |
496 | if (NULL != cp->t) | 500 | if (NULL != cp->t) |
497 | return; /* still relevant! */ | 501 | return; /* still relevant! */ |
498 | if (NULL != cp->core_mq) | 502 | if (NULL != cp->core_mq) |
499 | return; /* still relevant! */ | 503 | return; /* still relevant! */ |
500 | if (0 != GNUNET_CONTAINER_multishortmap_size(cp->connections)) | 504 | if (0 != GNUNET_CONTAINER_multishortmap_size (cp->connections)) |
501 | return; /* still relevant! */ | 505 | return; /* still relevant! */ |
502 | if ((NULL != cp->path_heap) && | 506 | if ((NULL != cp->path_heap) && |
503 | (0 < GNUNET_CONTAINER_heap_get_size(cp->path_heap))) | 507 | (0 < GNUNET_CONTAINER_heap_get_size (cp->path_heap))) |
504 | { | 508 | { |
505 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed(IDLE_PATH_TIMEOUT, | 509 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PATH_TIMEOUT, |
506 | &drop_paths, | 510 | &drop_paths, |
507 | cp); | 511 | cp); |
508 | return; | 512 | return; |
509 | } | 513 | } |
510 | if (0 != cp->num_paths) | 514 | if (0 != cp->num_paths) |
511 | return; /* still relevant! */ | 515 | return; /* still relevant! */ |
512 | if (NULL != cp->hello) | 516 | if (NULL != cp->hello) |
513 | { | 517 | { |
514 | /* relevant only until HELLO expires */ | 518 | /* relevant only until HELLO expires */ |
515 | exp = GNUNET_TIME_absolute_get_remaining(GNUNET_HELLO_get_last_expiration(cp->hello)); | 519 | exp = GNUNET_TIME_absolute_get_remaining (GNUNET_HELLO_get_last_expiration ( |
516 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed(exp, | 520 | cp->hello)); |
517 | &destroy_peer, | 521 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp, |
518 | cp); | 522 | &destroy_peer, |
519 | return; | 523 | cp); |
520 | } | 524 | return; |
521 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed(IDLE_PEER_TIMEOUT, | 525 | } |
522 | &destroy_peer, | 526 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PEER_TIMEOUT, |
523 | cp); | 527 | &destroy_peer, |
528 | cp); | ||
524 | } | 529 | } |
525 | 530 | ||
526 | 531 | ||
@@ -531,60 +536,60 @@ consider_peer_destroy(struct CadetPeer *cp) | |||
531 | * @param mq message queue to set (can be NULL) | 536 | * @param mq message queue to set (can be NULL) |
532 | */ | 537 | */ |
533 | void | 538 | void |
534 | GCP_set_mq(struct CadetPeer *cp, | 539 | GCP_set_mq (struct CadetPeer *cp, |
535 | struct GNUNET_MQ_Handle *mq) | 540 | struct GNUNET_MQ_Handle *mq) |
536 | { | 541 | { |
537 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 542 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
538 | "Message queue for peer %s is now %p\n", | 543 | "Message queue for peer %s is now %p\n", |
539 | GCP_2s(cp), | 544 | GCP_2s (cp), |
540 | mq); | 545 | mq); |
541 | cp->core_mq = mq; | 546 | cp->core_mq = mq; |
542 | for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next; | 547 | for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next; |
543 | NULL != mqm; | 548 | NULL != mqm; |
544 | mqm = next) | 549 | mqm = next) |
550 | { | ||
551 | /* Save next pointer in case mqm gets freed by the callback */ | ||
552 | next = mqm->next; | ||
553 | if (NULL == mq) | ||
545 | { | 554 | { |
546 | /* Save next pointer in case mqm gets freed by the callback */ | 555 | if (NULL != mqm->env) |
547 | next = mqm->next; | 556 | { |
548 | if (NULL == mq) | 557 | GNUNET_MQ_discard (mqm->env); |
549 | { | 558 | mqm->env = NULL; |
550 | if (NULL != mqm->env) | 559 | mqm->cb (mqm->cb_cls, |
551 | { | 560 | GNUNET_SYSERR); |
552 | GNUNET_MQ_discard(mqm->env); | 561 | } |
553 | mqm->env = NULL; | ||
554 | mqm->cb(mqm->cb_cls, | ||
555 | GNUNET_SYSERR); | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | mqm->cb(mqm->cb_cls, | ||
560 | GNUNET_NO); | ||
561 | } | ||
562 | } | ||
563 | else | 562 | else |
564 | { | 563 | { |
565 | GNUNET_assert(NULL == mqm->env); | 564 | mqm->cb (mqm->cb_cls, |
566 | mqm->cb(mqm->cb_cls, | 565 | GNUNET_NO); |
567 | GNUNET_YES); | 566 | } |
568 | } | 567 | } |
568 | else | ||
569 | { | ||
570 | GNUNET_assert (NULL == mqm->env); | ||
571 | mqm->cb (mqm->cb_cls, | ||
572 | GNUNET_YES); | ||
569 | } | 573 | } |
574 | } | ||
570 | if ((NULL != mq) || | 575 | if ((NULL != mq) || |
571 | (NULL != cp->t)) | 576 | (NULL != cp->t)) |
572 | consider_peer_activate(cp); | 577 | consider_peer_activate (cp); |
573 | else | 578 | else |
574 | consider_peer_destroy(cp); | 579 | consider_peer_destroy (cp); |
575 | 580 | ||
576 | if ((NULL != mq) && | 581 | if ((NULL != mq) && |
577 | (NULL != cp->t)) | 582 | (NULL != cp->t)) |
578 | { | 583 | { |
579 | /* have a new, direct path to the target, notify tunnel */ | 584 | /* have a new, direct path to the target, notify tunnel */ |
580 | struct CadetPeerPath *path; | 585 | struct CadetPeerPath *path; |
581 | 586 | ||
582 | path = GCPP_get_path_from_route(1, | 587 | path = GCPP_get_path_from_route (1, |
583 | &cp->pid); | 588 | &cp->pid); |
584 | GCT_consider_path(cp->t, | 589 | GCT_consider_path (cp->t, |
585 | path, | 590 | path, |
586 | 0); | 591 | 0); |
587 | } | 592 | } |
588 | } | 593 | } |
589 | 594 | ||
590 | 595 | ||
@@ -595,12 +600,12 @@ GCP_set_mq(struct CadetPeer *cp, | |||
595 | * @return #GNUNET_YES or #GNUNET_NO with the decision to drop. | 600 | * @return #GNUNET_YES or #GNUNET_NO with the decision to drop. |
596 | */ | 601 | */ |
597 | static int | 602 | static int |
598 | should_I_drop(void) | 603 | should_I_drop (void) |
599 | { | 604 | { |
600 | if (0 == drop_percent) | 605 | if (0 == drop_percent) |
601 | return GNUNET_NO; | 606 | return GNUNET_NO; |
602 | if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 607 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
603 | 101) < drop_percent) | 608 | 101) < drop_percent) |
604 | return GNUNET_YES; | 609 | return GNUNET_YES; |
605 | return GNUNET_NO; | 610 | return GNUNET_NO; |
606 | } | 611 | } |
@@ -613,7 +618,7 @@ should_I_drop(void) | |||
613 | * @param cls the `struct CadetPeeer` where we made progress | 618 | * @param cls the `struct CadetPeeer` where we made progress |
614 | */ | 619 | */ |
615 | static void | 620 | static void |
616 | mqm_send_done(void *cls); | 621 | mqm_send_done (void *cls); |
617 | 622 | ||
618 | 623 | ||
619 | /** | 624 | /** |
@@ -622,7 +627,7 @@ mqm_send_done(void *cls); | |||
622 | * @param mqm mqm to transmit message for now | 627 | * @param mqm mqm to transmit message for now |
623 | */ | 628 | */ |
624 | static void | 629 | static void |
625 | mqm_execute(struct GCP_MessageQueueManager *mqm) | 630 | mqm_execute (struct GCP_MessageQueueManager *mqm) |
626 | { | 631 | { |
627 | struct CadetPeer *cp = mqm->cp; | 632 | struct CadetPeer *cp = mqm->cp; |
628 | 633 | ||
@@ -632,59 +637,59 @@ mqm_execute(struct GCP_MessageQueueManager *mqm) | |||
632 | cp->mqm_ready_ptr = mqm->next; | 637 | cp->mqm_ready_ptr = mqm->next; |
633 | /* Move entry to the end of the DLL, to be fair. */ | 638 | /* Move entry to the end of the DLL, to be fair. */ |
634 | if (mqm != cp->mqm_tail) | 639 | if (mqm != cp->mqm_tail) |
635 | { | 640 | { |
636 | GNUNET_CONTAINER_DLL_remove(cp->mqm_head, | 641 | GNUNET_CONTAINER_DLL_remove (cp->mqm_head, |
637 | cp->mqm_tail, | 642 | cp->mqm_tail, |
638 | mqm); | 643 | mqm); |
639 | GNUNET_CONTAINER_DLL_insert_tail(cp->mqm_head, | 644 | GNUNET_CONTAINER_DLL_insert_tail (cp->mqm_head, |
640 | cp->mqm_tail, | 645 | cp->mqm_tail, |
641 | mqm); | 646 | mqm); |
642 | } | 647 | } |
643 | cp->mqm_ready_counter--; | 648 | cp->mqm_ready_counter--; |
644 | if (GNUNET_YES == should_I_drop()) | 649 | if (GNUNET_YES == should_I_drop ()) |
645 | { | 650 | { |
646 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 651 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
647 | "DROPPING message to peer %s from MQM %p\n", | 652 | "DROPPING message to peer %s from MQM %p\n", |
648 | GCP_2s(cp), | 653 | GCP_2s (cp), |
649 | mqm); | 654 | mqm); |
650 | GNUNET_MQ_discard(mqm->env); | 655 | GNUNET_MQ_discard (mqm->env); |
651 | mqm->env = NULL; | 656 | mqm->env = NULL; |
652 | mqm_send_done(cp); | 657 | mqm_send_done (cp); |
653 | } | 658 | } |
654 | else | 659 | else |
660 | { | ||
655 | { | 661 | { |
662 | const struct GNUNET_MessageHeader *mh; | ||
663 | |||
664 | mh = GNUNET_MQ_env_get_msg (mqm->env); | ||
665 | switch (ntohs (mh->type)) | ||
656 | { | 666 | { |
657 | const struct GNUNET_MessageHeader *mh; | 667 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX: |
658 | 668 | { | |
659 | mh = GNUNET_MQ_env_get_msg(mqm->env); | 669 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg |
660 | switch (ntohs(mh->type)) | 670 | = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *) mh; |
661 | { | 671 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
662 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX: | 672 | "P2P forwarding KX with ephemeral %s to %s on CID %s\n", |
663 | { | 673 | GNUNET_e2s (&msg->ephemeral_key), |
664 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg | 674 | GCP_2s (cp), |
665 | = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *)mh; | 675 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
666 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 676 | } |
667 | "P2P forwarding KX with ephemeral %s to %s on CID %s\n", | 677 | break; |
668 | GNUNET_e2s(&msg->ephemeral_key), | 678 | |
669 | GCP_2s(cp), | 679 | default: |
670 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | 680 | break; |
671 | } | ||
672 | break; | ||
673 | |||
674 | default: | ||
675 | break; | ||
676 | } | ||
677 | } | 681 | } |
678 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
679 | "Sending to peer %s from MQM %p\n", | ||
680 | GCP_2s(cp), | ||
681 | mqm); | ||
682 | GNUNET_MQ_send(cp->core_mq, | ||
683 | mqm->env); | ||
684 | mqm->env = NULL; | ||
685 | } | 682 | } |
686 | mqm->cb(mqm->cb_cls, | 683 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
687 | GNUNET_YES); | 684 | "Sending to peer %s from MQM %p\n", |
685 | GCP_2s (cp), | ||
686 | mqm); | ||
687 | GNUNET_MQ_send (cp->core_mq, | ||
688 | mqm->env); | ||
689 | mqm->env = NULL; | ||
690 | } | ||
691 | mqm->cb (mqm->cb_cls, | ||
692 | GNUNET_YES); | ||
688 | } | 693 | } |
689 | 694 | ||
690 | 695 | ||
@@ -696,7 +701,7 @@ mqm_execute(struct GCP_MessageQueueManager *mqm) | |||
696 | * @param cp peer to try to send the next ready message to | 701 | * @param cp peer to try to send the next ready message to |
697 | */ | 702 | */ |
698 | static void | 703 | static void |
699 | send_next_ready(struct CadetPeer *cp) | 704 | send_next_ready (struct CadetPeer *cp) |
700 | { | 705 | { |
701 | struct GCP_MessageQueueManager *mqm; | 706 | struct GCP_MessageQueueManager *mqm; |
702 | 707 | ||
@@ -707,7 +712,7 @@ send_next_ready(struct CadetPeer *cp) | |||
707 | cp->mqm_ready_ptr = mqm->next; | 712 | cp->mqm_ready_ptr = mqm->next; |
708 | if (NULL == mqm) | 713 | if (NULL == mqm) |
709 | return; /* nothing to do */ | 714 | return; /* nothing to do */ |
710 | mqm_execute(mqm); | 715 | mqm_execute (mqm); |
711 | } | 716 | } |
712 | 717 | ||
713 | 718 | ||
@@ -718,14 +723,14 @@ send_next_ready(struct CadetPeer *cp) | |||
718 | * @param cls the `struct CadetPeeer` where we made progress | 723 | * @param cls the `struct CadetPeeer` where we made progress |
719 | */ | 724 | */ |
720 | static void | 725 | static void |
721 | mqm_send_done(void *cls) | 726 | mqm_send_done (void *cls) |
722 | { | 727 | { |
723 | struct CadetPeer *cp = cls; | 728 | struct CadetPeer *cp = cls; |
724 | 729 | ||
725 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 730 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
726 | "Sending to peer %s completed\n", | 731 | "Sending to peer %s completed\n", |
727 | GCP_2s(cp)); | 732 | GCP_2s (cp)); |
728 | send_next_ready(cp); | 733 | send_next_ready (cp); |
729 | } | 734 | } |
730 | 735 | ||
731 | 736 | ||
@@ -737,30 +742,30 @@ mqm_send_done(void *cls) | |||
737 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it | 742 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it |
738 | */ | 743 | */ |
739 | void | 744 | void |
740 | GCP_send(struct GCP_MessageQueueManager *mqm, | 745 | GCP_send (struct GCP_MessageQueueManager *mqm, |
741 | struct GNUNET_MQ_Envelope *env) | 746 | struct GNUNET_MQ_Envelope *env) |
742 | { | 747 | { |
743 | struct CadetPeer *cp = mqm->cp; | 748 | struct CadetPeer *cp = mqm->cp; |
744 | 749 | ||
745 | GNUNET_assert(NULL != env); | 750 | GNUNET_assert (NULL != env); |
746 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 751 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
747 | "Queueing message to peer %s in MQM %p\n", | 752 | "Queueing message to peer %s in MQM %p\n", |
748 | GCP_2s(cp), | 753 | GCP_2s (cp), |
749 | mqm); | 754 | mqm); |
750 | GNUNET_assert(NULL != cp->core_mq); | 755 | GNUNET_assert (NULL != cp->core_mq); |
751 | GNUNET_assert(NULL == mqm->env); | 756 | GNUNET_assert (NULL == mqm->env); |
752 | GNUNET_MQ_notify_sent(env, | 757 | GNUNET_MQ_notify_sent (env, |
753 | &mqm_send_done, | 758 | &mqm_send_done, |
754 | cp); | 759 | cp); |
755 | mqm->env = env; | 760 | mqm->env = env; |
756 | cp->mqm_ready_counter++; | 761 | cp->mqm_ready_counter++; |
757 | if (mqm != cp->mqm_ready_ptr) | 762 | if (mqm != cp->mqm_ready_ptr) |
758 | cp->mqm_ready_ptr = cp->mqm_head; | 763 | cp->mqm_ready_ptr = cp->mqm_head; |
759 | if (1 == cp->mqm_ready_counter) | 764 | if (1 == cp->mqm_ready_counter) |
760 | cp->mqm_ready_ptr = mqm; | 765 | cp->mqm_ready_ptr = mqm; |
761 | if (0 != GNUNET_MQ_get_length(cp->core_mq)) | 766 | if (0 != GNUNET_MQ_get_length (cp->core_mq)) |
762 | return; | 767 | return; |
763 | send_next_ready(cp); | 768 | send_next_ready (cp); |
764 | } | 769 | } |
765 | 770 | ||
766 | 771 | ||
@@ -773,18 +778,18 @@ GCP_send(struct GCP_MessageQueueManager *mqm, | |||
773 | * @return #GNUNET_OK (continue to iterate) | 778 | * @return #GNUNET_OK (continue to iterate) |
774 | */ | 779 | */ |
775 | static int | 780 | static int |
776 | destroy_iterator_cb(void *cls, | 781 | destroy_iterator_cb (void *cls, |
777 | const struct GNUNET_PeerIdentity *pid, | 782 | const struct GNUNET_PeerIdentity *pid, |
778 | void *value) | 783 | void *value) |
779 | { | 784 | { |
780 | struct CadetPeer *cp = value; | 785 | struct CadetPeer *cp = value; |
781 | 786 | ||
782 | if (NULL != cp->destroy_task) | 787 | if (NULL != cp->destroy_task) |
783 | { | 788 | { |
784 | GNUNET_SCHEDULER_cancel(cp->destroy_task); | 789 | GNUNET_SCHEDULER_cancel (cp->destroy_task); |
785 | cp->destroy_task = NULL; | 790 | cp->destroy_task = NULL; |
786 | } | 791 | } |
787 | destroy_peer(cp); | 792 | destroy_peer (cp); |
788 | return GNUNET_OK; | 793 | return GNUNET_OK; |
789 | } | 794 | } |
790 | 795 | ||
@@ -795,13 +800,13 @@ destroy_iterator_cb(void *cls, | |||
795 | * connections are down. | 800 | * connections are down. |
796 | */ | 801 | */ |
797 | void | 802 | void |
798 | GCP_destroy_all_peers() | 803 | GCP_destroy_all_peers () |
799 | { | 804 | { |
800 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 805 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
801 | "Destroying all peers now\n"); | 806 | "Destroying all peers now\n"); |
802 | GNUNET_CONTAINER_multipeermap_iterate(peers, | 807 | GNUNET_CONTAINER_multipeermap_iterate (peers, |
803 | &destroy_iterator_cb, | 808 | &destroy_iterator_cb, |
804 | NULL); | 809 | NULL); |
805 | } | 810 | } |
806 | 811 | ||
807 | 812 | ||
@@ -812,17 +817,17 @@ GCP_destroy_all_peers() | |||
812 | * @param cp peer to drop paths to | 817 | * @param cp peer to drop paths to |
813 | */ | 818 | */ |
814 | void | 819 | void |
815 | GCP_drop_owned_paths(struct CadetPeer *cp) | 820 | GCP_drop_owned_paths (struct CadetPeer *cp) |
816 | { | 821 | { |
817 | struct CadetPeerPath *path; | 822 | struct CadetPeerPath *path; |
818 | 823 | ||
819 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 824 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
820 | "Destroying all paths to %s\n", | 825 | "Destroying all paths to %s\n", |
821 | GCP_2s(cp)); | 826 | GCP_2s (cp)); |
822 | while (NULL != (path = | 827 | while (NULL != (path = |
823 | GNUNET_CONTAINER_heap_remove_root(cp->path_heap))) | 828 | GNUNET_CONTAINER_heap_remove_root (cp->path_heap))) |
824 | GCPP_release(path); | 829 | GCPP_release (path); |
825 | GNUNET_CONTAINER_heap_destroy(cp->path_heap); | 830 | GNUNET_CONTAINER_heap_destroy (cp->path_heap); |
826 | cp->path_heap = NULL; | 831 | cp->path_heap = NULL; |
827 | } | 832 | } |
828 | 833 | ||
@@ -835,55 +840,55 @@ GCP_drop_owned_paths(struct CadetPeer *cp) | |||
835 | * @param off offset of this peer on the path | 840 | * @param off offset of this peer on the path |
836 | */ | 841 | */ |
837 | void | 842 | void |
838 | GCP_path_entry_add(struct CadetPeer *cp, | 843 | GCP_path_entry_add (struct CadetPeer *cp, |
839 | struct CadetPeerPathEntry *entry, | 844 | struct CadetPeerPathEntry *entry, |
840 | unsigned int off) | 845 | unsigned int off) |
841 | { | 846 | { |
842 | GNUNET_assert(cp == GCPP_get_peer_at_offset(entry->path, | 847 | GNUNET_assert (cp == GCPP_get_peer_at_offset (entry->path, |
843 | off)); | 848 | off)); |
844 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 849 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
845 | "Discovered that peer %s is on path %s at offset %u\n", | 850 | "Discovered that peer %s is on path %s at offset %u\n", |
846 | GCP_2s(cp), | 851 | GCP_2s (cp), |
847 | GCPP_2s(entry->path), | 852 | GCPP_2s (entry->path), |
848 | off); | 853 | off); |
849 | if (off >= cp->path_dll_length) | 854 | if (off >= cp->path_dll_length) |
850 | { | 855 | { |
851 | unsigned int len = cp->path_dll_length; | 856 | unsigned int len = cp->path_dll_length; |
852 | 857 | ||
853 | GNUNET_array_grow(cp->path_heads, | 858 | GNUNET_array_grow (cp->path_heads, |
854 | len, | 859 | len, |
855 | off + 4); | 860 | off + 4); |
856 | GNUNET_array_grow(cp->path_tails, | 861 | GNUNET_array_grow (cp->path_tails, |
857 | cp->path_dll_length, | 862 | cp->path_dll_length, |
858 | off + 4); | 863 | off + 4); |
859 | } | 864 | } |
860 | GNUNET_CONTAINER_DLL_insert(cp->path_heads[off], | 865 | GNUNET_CONTAINER_DLL_insert (cp->path_heads[off], |
861 | cp->path_tails[off], | 866 | cp->path_tails[off], |
862 | entry); | 867 | entry); |
863 | cp->off_sum += off; | 868 | cp->off_sum += off; |
864 | cp->num_paths++; | 869 | cp->num_paths++; |
865 | 870 | ||
866 | /* If we have a tunnel to this peer, tell the tunnel that there is a | 871 | /* If we have a tunnel to this peer, tell the tunnel that there is a |
867 | new path available. */ | 872 | new path available. */ |
868 | if (NULL != cp->t) | 873 | if (NULL != cp->t) |
869 | GCT_consider_path(cp->t, | 874 | GCT_consider_path (cp->t, |
870 | entry->path, | 875 | entry->path, |
871 | off); | 876 | off); |
872 | 877 | ||
873 | if ((NULL != cp->search_h) && | 878 | if ((NULL != cp->search_h) && |
874 | (DESIRED_CONNECTIONS_PER_TUNNEL <= cp->num_paths)) | 879 | (DESIRED_CONNECTIONS_PER_TUNNEL <= cp->num_paths)) |
875 | { | 880 | { |
876 | /* Now I have enough paths, stop search */ | 881 | /* Now I have enough paths, stop search */ |
877 | GCD_search_stop(cp->search_h); | 882 | GCD_search_stop (cp->search_h); |
878 | cp->search_h = NULL; | 883 | cp->search_h = NULL; |
879 | } | 884 | } |
880 | if (NULL != cp->destroy_task) | 885 | if (NULL != cp->destroy_task) |
881 | { | 886 | { |
882 | /* paths changed, this resets the destroy timeout counter | 887 | /* paths changed, this resets the destroy timeout counter |
883 | and aborts a destroy task that may no longer be valid | 888 | and aborts a destroy task that may no longer be valid |
884 | to have (as we now have more paths via this peer). */ | 889 | to have (as we now have more paths via this peer). */ |
885 | consider_peer_destroy(cp); | 890 | consider_peer_destroy (cp); |
886 | } | 891 | } |
887 | } | 892 | } |
888 | 893 | ||
889 | 894 | ||
@@ -895,19 +900,19 @@ GCP_path_entry_add(struct CadetPeer *cp, | |||
895 | * @param off offset of this peer on the path | 900 | * @param off offset of this peer on the path |
896 | */ | 901 | */ |
897 | void | 902 | void |
898 | GCP_path_entry_remove(struct CadetPeer *cp, | 903 | GCP_path_entry_remove (struct CadetPeer *cp, |
899 | struct CadetPeerPathEntry *entry, | 904 | struct CadetPeerPathEntry *entry, |
900 | unsigned int off) | 905 | unsigned int off) |
901 | { | 906 | { |
902 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 907 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
903 | "Removing knowledge about peer %s beging on path %s at offset %u\n", | 908 | "Removing knowledge about peer %s beging on path %s at offset %u\n", |
904 | GCP_2s(cp), | 909 | GCP_2s (cp), |
905 | GCPP_2s(entry->path), | 910 | GCPP_2s (entry->path), |
906 | off); | 911 | off); |
907 | GNUNET_CONTAINER_DLL_remove(cp->path_heads[off], | 912 | GNUNET_CONTAINER_DLL_remove (cp->path_heads[off], |
908 | cp->path_tails[off], | 913 | cp->path_tails[off], |
909 | entry); | 914 | entry); |
910 | GNUNET_assert(0 < cp->num_paths); | 915 | GNUNET_assert (0 < cp->num_paths); |
911 | cp->off_sum -= off; | 916 | cp->off_sum -= off; |
912 | cp->num_paths--; | 917 | cp->num_paths--; |
913 | if ((NULL == cp->core_mq) && | 918 | if ((NULL == cp->core_mq) && |
@@ -915,12 +920,12 @@ GCP_path_entry_remove(struct CadetPeer *cp, | |||
915 | (NULL == cp->search_h) && | 920 | (NULL == cp->search_h) && |
916 | (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths)) | 921 | (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths)) |
917 | cp->search_h | 922 | cp->search_h |
918 | = GCD_search(&cp->pid); | 923 | = GCD_search (&cp->pid); |
919 | if (NULL == cp->destroy_task) | 924 | if (NULL == cp->destroy_task) |
920 | { | 925 | { |
921 | /* paths changed, we might now be ready for destruction, check again */ | 926 | /* paths changed, we might now be ready for destruction, check again */ |
922 | consider_peer_destroy(cp); | 927 | consider_peer_destroy (cp); |
923 | } | 928 | } |
924 | } | 929 | } |
925 | 930 | ||
926 | 931 | ||
@@ -931,32 +936,32 @@ GCP_path_entry_remove(struct CadetPeer *cp, | |||
931 | * @param cls the `struct CadetPeer` to maintain the path heap for | 936 | * @param cls the `struct CadetPeer` to maintain the path heap for |
932 | */ | 937 | */ |
933 | static void | 938 | static void |
934 | path_heap_cleanup(void *cls) | 939 | path_heap_cleanup (void *cls) |
935 | { | 940 | { |
936 | struct CadetPeer *cp = cls; | 941 | struct CadetPeer *cp = cls; |
937 | struct CadetPeerPath *root; | 942 | struct CadetPeerPath *root; |
938 | 943 | ||
939 | cp->heap_cleanup_task = NULL; | 944 | cp->heap_cleanup_task = NULL; |
940 | while (GNUNET_CONTAINER_heap_get_size(cp->path_heap) >= | 945 | while (GNUNET_CONTAINER_heap_get_size (cp->path_heap) >= |
941 | 2 * DESIRED_CONNECTIONS_PER_TUNNEL) | 946 | 2 * DESIRED_CONNECTIONS_PER_TUNNEL) |
942 | { | 947 | { |
943 | /* Now we have way too many, drop least desirable UNLESS it is in use! | 948 | /* Now we have way too many, drop least desirable UNLESS it is in use! |
944 | (Note that this intentionally keeps highly desireable, but currently | 949 | (Note that this intentionally keeps highly desireable, but currently |
945 | unused paths around in the hope that we might be able to switch, even | 950 | unused paths around in the hope that we might be able to switch, even |
946 | if the number of paths exceeds the threshold.) */ | 951 | if the number of paths exceeds the threshold.) */ |
947 | root = GNUNET_CONTAINER_heap_peek(cp->path_heap); | 952 | root = GNUNET_CONTAINER_heap_peek (cp->path_heap); |
948 | GNUNET_assert(NULL != root); | 953 | GNUNET_assert (NULL != root); |
949 | if (NULL != | 954 | if (NULL != |
950 | GCPP_get_connection(root, | 955 | GCPP_get_connection (root, |
951 | cp, | 956 | cp, |
952 | GCPP_get_length(root) - 1)) | 957 | GCPP_get_length (root) - 1)) |
953 | break; /* can't fix */ | 958 | break; /* can't fix */ |
954 | /* Got plenty of paths to this destination, and this is a low-quality | 959 | /* Got plenty of paths to this destination, and this is a low-quality |
955 | one that we don't care about. Allow it to die. */ | 960 | one that we don't care about. Allow it to die. */ |
956 | GNUNET_assert(root == | 961 | GNUNET_assert (root == |
957 | GNUNET_CONTAINER_heap_remove_root(cp->path_heap)); | 962 | GNUNET_CONTAINER_heap_remove_root (cp->path_heap)); |
958 | GCPP_release(root); | 963 | GCPP_release (root); |
959 | } | 964 | } |
960 | } | 965 | } |
961 | 966 | ||
962 | 967 | ||
@@ -972,66 +977,66 @@ path_heap_cleanup(void *cls) | |||
972 | * otherwise the node in the peer's path heap for the @a path. | 977 | * otherwise the node in the peer's path heap for the @a path. |
973 | */ | 978 | */ |
974 | struct GNUNET_CONTAINER_HeapNode * | 979 | struct GNUNET_CONTAINER_HeapNode * |
975 | GCP_attach_path(struct CadetPeer *cp, | 980 | GCP_attach_path (struct CadetPeer *cp, |
976 | struct CadetPeerPath *path, | 981 | struct CadetPeerPath *path, |
977 | unsigned int off, | 982 | unsigned int off, |
978 | int force) | 983 | int force) |
979 | { | 984 | { |
980 | GNUNET_CONTAINER_HeapCostType desirability; | 985 | GNUNET_CONTAINER_HeapCostType desirability; |
981 | struct CadetPeerPath *root; | 986 | struct CadetPeerPath *root; |
982 | GNUNET_CONTAINER_HeapCostType root_desirability; | 987 | GNUNET_CONTAINER_HeapCostType root_desirability; |
983 | struct GNUNET_CONTAINER_HeapNode *hn; | 988 | struct GNUNET_CONTAINER_HeapNode *hn; |
984 | 989 | ||
985 | GNUNET_assert(off == GCPP_get_length(path) - 1); | 990 | GNUNET_assert (off == GCPP_get_length (path) - 1); |
986 | GNUNET_assert(cp == GCPP_get_peer_at_offset(path, | 991 | GNUNET_assert (cp == GCPP_get_peer_at_offset (path, |
987 | off)); | 992 | off)); |
988 | if (NULL == cp->path_heap) | 993 | if (NULL == cp->path_heap) |
989 | { | 994 | { |
990 | /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */ | 995 | /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */ |
991 | GNUNET_assert(GNUNET_NO == force); | 996 | GNUNET_assert (GNUNET_NO == force); |
992 | return NULL; | 997 | return NULL; |
993 | } | 998 | } |
994 | desirability = GCPP_get_desirability(path); | 999 | desirability = GCPP_get_desirability (path); |
995 | if (GNUNET_NO == force) | 1000 | if (GNUNET_NO == force) |
1001 | { | ||
1002 | /* FIXME: desirability is not yet initialized; tricky! */ | ||
1003 | if (GNUNET_NO == | ||
1004 | GNUNET_CONTAINER_heap_peek2 (cp->path_heap, | ||
1005 | (void **) &root, | ||
1006 | &root_desirability)) | ||
996 | { | 1007 | { |
997 | /* FIXME: desirability is not yet initialized; tricky! */ | 1008 | root = NULL; |
998 | if (GNUNET_NO == | 1009 | root_desirability = 0; |
999 | GNUNET_CONTAINER_heap_peek2(cp->path_heap, | 1010 | } |
1000 | (void **)&root, | ||
1001 | &root_desirability)) | ||
1002 | { | ||
1003 | root = NULL; | ||
1004 | root_desirability = 0; | ||
1005 | } | ||
1006 | 1011 | ||
1007 | if ((DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) && | 1012 | if ((DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) && |
1008 | (desirability < root_desirability)) | 1013 | (desirability < root_desirability)) |
1009 | { | 1014 | { |
1010 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1015 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1011 | "Decided to not attach path %s to peer %s due to undesirability\n", | 1016 | "Decided to not attach path %s to peer %s due to undesirability\n", |
1012 | GCPP_2s(path), | 1017 | GCPP_2s (path), |
1013 | GCP_2s(cp)); | 1018 | GCP_2s (cp)); |
1014 | return NULL; | 1019 | return NULL; |
1015 | } | ||
1016 | } | 1020 | } |
1021 | } | ||
1017 | 1022 | ||
1018 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1023 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1019 | "Attaching path %s to peer %s (%s)\n", | 1024 | "Attaching path %s to peer %s (%s)\n", |
1020 | GCPP_2s(path), | 1025 | GCPP_2s (path), |
1021 | GCP_2s(cp), | 1026 | GCP_2s (cp), |
1022 | (GNUNET_NO == force) ? "desirable" : "forced"); | 1027 | (GNUNET_NO == force) ? "desirable" : "forced"); |
1023 | 1028 | ||
1024 | /* Yes, we'd like to add this path, add to our heap */ | 1029 | /* Yes, we'd like to add this path, add to our heap */ |
1025 | hn = GNUNET_CONTAINER_heap_insert(cp->path_heap, | 1030 | hn = GNUNET_CONTAINER_heap_insert (cp->path_heap, |
1026 | path, | 1031 | path, |
1027 | desirability); | 1032 | desirability); |
1028 | 1033 | ||
1029 | /* Consider maybe dropping other paths because of the new one */ | 1034 | /* Consider maybe dropping other paths because of the new one */ |
1030 | if ((GNUNET_CONTAINER_heap_get_size(cp->path_heap) >= | 1035 | if ((GNUNET_CONTAINER_heap_get_size (cp->path_heap) >= |
1031 | 2 * DESIRED_CONNECTIONS_PER_TUNNEL) && | 1036 | 2 * DESIRED_CONNECTIONS_PER_TUNNEL) && |
1032 | (NULL != cp->heap_cleanup_task)) | 1037 | (NULL != cp->heap_cleanup_task)) |
1033 | cp->heap_cleanup_task = GNUNET_SCHEDULER_add_now(&path_heap_cleanup, | 1038 | cp->heap_cleanup_task = GNUNET_SCHEDULER_add_now (&path_heap_cleanup, |
1034 | cp); | 1039 | cp); |
1035 | return hn; | 1040 | return hn; |
1036 | } | 1041 | } |
1037 | 1042 | ||
@@ -1046,16 +1051,16 @@ GCP_attach_path(struct CadetPeer *cp, | |||
1046 | * @param hn note in @a cp's path heap that must be deleted | 1051 | * @param hn note in @a cp's path heap that must be deleted |
1047 | */ | 1052 | */ |
1048 | void | 1053 | void |
1049 | GCP_detach_path(struct CadetPeer *cp, | 1054 | GCP_detach_path (struct CadetPeer *cp, |
1050 | struct CadetPeerPath *path, | 1055 | struct CadetPeerPath *path, |
1051 | struct GNUNET_CONTAINER_HeapNode *hn) | 1056 | struct GNUNET_CONTAINER_HeapNode *hn) |
1052 | { | 1057 | { |
1053 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1058 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1054 | "Detatching path %s from peer %s\n", | 1059 | "Detatching path %s from peer %s\n", |
1055 | GCPP_2s(path), | 1060 | GCPP_2s (path), |
1056 | GCP_2s(cp)); | 1061 | GCP_2s (cp)); |
1057 | GNUNET_assert(path == | 1062 | GNUNET_assert (path == |
1058 | GNUNET_CONTAINER_heap_remove_node(hn)); | 1063 | GNUNET_CONTAINER_heap_remove_node (hn)); |
1059 | } | 1064 | } |
1060 | 1065 | ||
1061 | 1066 | ||
@@ -1066,23 +1071,24 @@ GCP_detach_path(struct CadetPeer *cp, | |||
1066 | * @param cc the connection to add | 1071 | * @param cc the connection to add |
1067 | */ | 1072 | */ |
1068 | void | 1073 | void |
1069 | GCP_add_connection(struct CadetPeer *cp, | 1074 | GCP_add_connection (struct CadetPeer *cp, |
1070 | struct CadetConnection *cc) | 1075 | struct CadetConnection *cc) |
1071 | { | 1076 | { |
1072 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1077 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1073 | "Adding %s to peer %s\n", | 1078 | "Adding %s to peer %s\n", |
1074 | GCC_2s(cc), | 1079 | GCC_2s (cc), |
1075 | GCP_2s(cp)); | 1080 | GCP_2s (cp)); |
1076 | GNUNET_assert(GNUNET_OK == | 1081 | GNUNET_assert (GNUNET_OK == |
1077 | GNUNET_CONTAINER_multishortmap_put(cp->connections, | 1082 | GNUNET_CONTAINER_multishortmap_put (cp->connections, |
1078 | &GCC_get_id(cc)->connection_of_tunnel, | 1083 | &GCC_get_id ( |
1079 | cc, | 1084 | cc)->connection_of_tunnel, |
1080 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1085 | cc, |
1086 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1081 | if (NULL != cp->destroy_task) | 1087 | if (NULL != cp->destroy_task) |
1082 | { | 1088 | { |
1083 | GNUNET_SCHEDULER_cancel(cp->destroy_task); | 1089 | GNUNET_SCHEDULER_cancel (cp->destroy_task); |
1084 | cp->destroy_task = NULL; | 1090 | cp->destroy_task = NULL; |
1085 | } | 1091 | } |
1086 | } | 1092 | } |
1087 | 1093 | ||
1088 | 1094 | ||
@@ -1093,18 +1099,20 @@ GCP_add_connection(struct CadetPeer *cp, | |||
1093 | * @param cc the connection to remove | 1099 | * @param cc the connection to remove |
1094 | */ | 1100 | */ |
1095 | void | 1101 | void |
1096 | GCP_remove_connection(struct CadetPeer *cp, | 1102 | GCP_remove_connection (struct CadetPeer *cp, |
1097 | struct CadetConnection *cc) | 1103 | struct CadetConnection *cc) |
1098 | { | 1104 | { |
1099 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1105 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1100 | "Removing connection %s from peer %s\n", | 1106 | "Removing connection %s from peer %s\n", |
1101 | GCC_2s(cc), | 1107 | GCC_2s (cc), |
1102 | GCP_2s(cp)); | 1108 | GCP_2s (cp)); |
1103 | GNUNET_assert(GNUNET_YES == | 1109 | GNUNET_assert (GNUNET_YES == |
1104 | GNUNET_CONTAINER_multishortmap_remove(cp->connections, | 1110 | GNUNET_CONTAINER_multishortmap_remove (cp->connections, |
1105 | &GCC_get_id(cc)->connection_of_tunnel, | 1111 | &GCC_get_id ( |
1106 | cc)); | 1112 | cc)-> |
1107 | consider_peer_destroy(cp); | 1113 | connection_of_tunnel, |
1114 | cc)); | ||
1115 | consider_peer_destroy (cp); | ||
1108 | } | 1116 | } |
1109 | 1117 | ||
1110 | 1118 | ||
@@ -1120,30 +1128,31 @@ GCP_remove_connection(struct CadetPeer *cp, | |||
1120 | * NULL if unknown and not requested @a create | 1128 | * NULL if unknown and not requested @a create |
1121 | */ | 1129 | */ |
1122 | struct CadetPeer * | 1130 | struct CadetPeer * |
1123 | GCP_get(const struct GNUNET_PeerIdentity *peer_id, | 1131 | GCP_get (const struct GNUNET_PeerIdentity *peer_id, |
1124 | int create) | 1132 | int create) |
1125 | { | 1133 | { |
1126 | struct CadetPeer *cp; | 1134 | struct CadetPeer *cp; |
1127 | 1135 | ||
1128 | cp = GNUNET_CONTAINER_multipeermap_get(peers, | 1136 | cp = GNUNET_CONTAINER_multipeermap_get (peers, |
1129 | peer_id); | 1137 | peer_id); |
1130 | if (NULL != cp) | 1138 | if (NULL != cp) |
1131 | return cp; | 1139 | return cp; |
1132 | if (GNUNET_NO == create) | 1140 | if (GNUNET_NO == create) |
1133 | return NULL; | 1141 | return NULL; |
1134 | cp = GNUNET_new(struct CadetPeer); | 1142 | cp = GNUNET_new (struct CadetPeer); |
1135 | cp->pid = *peer_id; | 1143 | cp->pid = *peer_id; |
1136 | cp->connections = GNUNET_CONTAINER_multishortmap_create(32, | 1144 | cp->connections = GNUNET_CONTAINER_multishortmap_create (32, |
1137 | GNUNET_YES); | 1145 | GNUNET_YES); |
1138 | cp->path_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1146 | cp->path_heap = GNUNET_CONTAINER_heap_create ( |
1139 | GNUNET_assert(GNUNET_YES == | 1147 | GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1140 | GNUNET_CONTAINER_multipeermap_put(peers, | 1148 | GNUNET_assert (GNUNET_YES == |
1141 | &cp->pid, | 1149 | GNUNET_CONTAINER_multipeermap_put (peers, |
1142 | cp, | 1150 | &cp->pid, |
1143 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1151 | cp, |
1144 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1152 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1145 | "Creating peer %s\n", | 1153 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1146 | GCP_2s(cp)); | 1154 | "Creating peer %s\n", |
1155 | GCP_2s (cp)); | ||
1147 | return cp; | 1156 | return cp; |
1148 | } | 1157 | } |
1149 | 1158 | ||
@@ -1155,7 +1164,7 @@ GCP_get(const struct GNUNET_PeerIdentity *peer_id, | |||
1155 | * @return the peer identity | 1164 | * @return the peer identity |
1156 | */ | 1165 | */ |
1157 | const struct GNUNET_PeerIdentity * | 1166 | const struct GNUNET_PeerIdentity * |
1158 | GCP_get_id(struct CadetPeer *cp) | 1167 | GCP_get_id (struct CadetPeer *cp) |
1159 | { | 1168 | { |
1160 | return &cp->pid; | 1169 | return &cp->pid; |
1161 | } | 1170 | } |
@@ -1168,12 +1177,12 @@ GCP_get_id(struct CadetPeer *cp) | |||
1168 | * @param cls Closure for @c iter. | 1177 | * @param cls Closure for @c iter. |
1169 | */ | 1178 | */ |
1170 | void | 1179 | void |
1171 | GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter, | 1180 | GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, |
1172 | void *cls) | 1181 | void *cls) |
1173 | { | 1182 | { |
1174 | GNUNET_CONTAINER_multipeermap_iterate(peers, | 1183 | GNUNET_CONTAINER_multipeermap_iterate (peers, |
1175 | iter, | 1184 | iter, |
1176 | cls); | 1185 | cls); |
1177 | } | 1186 | } |
1178 | 1187 | ||
1179 | 1188 | ||
@@ -1184,7 +1193,7 @@ GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter, | |||
1184 | * @return Number of known paths. | 1193 | * @return Number of known paths. |
1185 | */ | 1194 | */ |
1186 | unsigned int | 1195 | unsigned int |
1187 | GCP_count_paths(const struct CadetPeer *cp) | 1196 | GCP_count_paths (const struct CadetPeer *cp) |
1188 | { | 1197 | { |
1189 | return cp->num_paths; | 1198 | return cp->num_paths; |
1190 | } | 1199 | } |
@@ -1199,45 +1208,45 @@ GCP_count_paths(const struct CadetPeer *cp) | |||
1199 | * @return Number of iterated paths. | 1208 | * @return Number of iterated paths. |
1200 | */ | 1209 | */ |
1201 | unsigned int | 1210 | unsigned int |
1202 | GCP_iterate_paths(struct CadetPeer *cp, | 1211 | GCP_iterate_paths (struct CadetPeer *cp, |
1203 | GCP_PathIterator callback, | 1212 | GCP_PathIterator callback, |
1204 | void *callback_cls) | 1213 | void *callback_cls) |
1205 | { | 1214 | { |
1206 | unsigned int ret = 0; | 1215 | unsigned int ret = 0; |
1207 | 1216 | ||
1208 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1217 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1209 | "Iterating over paths to peer %s%s\n", | 1218 | "Iterating over paths to peer %s%s\n", |
1210 | GCP_2s(cp), | 1219 | GCP_2s (cp), |
1211 | (NULL == cp->core_mq) ? "" : " including direct link"); | 1220 | (NULL == cp->core_mq) ? "" : " including direct link"); |
1212 | if (NULL != cp->core_mq) | 1221 | if (NULL != cp->core_mq) |
1222 | { | ||
1223 | /* FIXME: this branch seems to duplicate the | ||
1224 | i=0 case below (direct link). Leave out!??? -CG */ | ||
1225 | struct CadetPeerPath *path; | ||
1226 | |||
1227 | path = GCPP_get_path_from_route (1, | ||
1228 | &cp->pid); | ||
1229 | ret++; | ||
1230 | if (GNUNET_NO == | ||
1231 | callback (callback_cls, | ||
1232 | path, | ||
1233 | 0)) | ||
1234 | return ret; | ||
1235 | } | ||
1236 | for (unsigned int i = 0; i < cp->path_dll_length; i++) | ||
1237 | { | ||
1238 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; | ||
1239 | NULL != pe; | ||
1240 | pe = pe->next) | ||
1213 | { | 1241 | { |
1214 | /* FIXME: this branch seems to duplicate the | ||
1215 | i=0 case below (direct link). Leave out!??? -CG */ | ||
1216 | struct CadetPeerPath *path; | ||
1217 | |||
1218 | path = GCPP_get_path_from_route(1, | ||
1219 | &cp->pid); | ||
1220 | ret++; | 1242 | ret++; |
1221 | if (GNUNET_NO == | 1243 | if (GNUNET_NO == |
1222 | callback(callback_cls, | 1244 | callback (callback_cls, |
1223 | path, | 1245 | pe->path, |
1224 | 0)) | 1246 | i)) |
1225 | return ret; | 1247 | return ret; |
1226 | } | 1248 | } |
1227 | for (unsigned int i = 0; i < cp->path_dll_length; i++) | 1249 | } |
1228 | { | ||
1229 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; | ||
1230 | NULL != pe; | ||
1231 | pe = pe->next) | ||
1232 | { | ||
1233 | ret++; | ||
1234 | if (GNUNET_NO == | ||
1235 | callback(callback_cls, | ||
1236 | pe->path, | ||
1237 | i)) | ||
1238 | return ret; | ||
1239 | } | ||
1240 | } | ||
1241 | return ret; | 1250 | return ret; |
1242 | } | 1251 | } |
1243 | 1252 | ||
@@ -1250,29 +1259,29 @@ GCP_iterate_paths(struct CadetPeer *cp, | |||
1250 | * @return Number of iterated paths. | 1259 | * @return Number of iterated paths. |
1251 | */ | 1260 | */ |
1252 | unsigned int | 1261 | unsigned int |
1253 | GCP_iterate_indirect_paths(struct CadetPeer *cp, | 1262 | GCP_iterate_indirect_paths (struct CadetPeer *cp, |
1254 | GCP_PathIterator callback, | 1263 | GCP_PathIterator callback, |
1255 | void *callback_cls) | 1264 | void *callback_cls) |
1256 | { | 1265 | { |
1257 | unsigned int ret = 0; | 1266 | unsigned int ret = 0; |
1258 | 1267 | ||
1259 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1268 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1260 | "Iterating over paths to peer %s without direct link\n", | 1269 | "Iterating over paths to peer %s without direct link\n", |
1261 | GCP_2s(cp)); | 1270 | GCP_2s (cp)); |
1262 | for (unsigned int i = 1; i < cp->path_dll_length; i++) | 1271 | for (unsigned int i = 1; i < cp->path_dll_length; i++) |
1272 | { | ||
1273 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; | ||
1274 | NULL != pe; | ||
1275 | pe = pe->next) | ||
1263 | { | 1276 | { |
1264 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; | 1277 | ret++; |
1265 | NULL != pe; | 1278 | if (GNUNET_NO == |
1266 | pe = pe->next) | 1279 | callback (callback_cls, |
1267 | { | 1280 | pe->path, |
1268 | ret++; | 1281 | i)) |
1269 | if (GNUNET_NO == | 1282 | return ret; |
1270 | callback(callback_cls, | ||
1271 | pe->path, | ||
1272 | i)) | ||
1273 | return ret; | ||
1274 | } | ||
1275 | } | 1283 | } |
1284 | } | ||
1276 | return ret; | 1285 | return ret; |
1277 | } | 1286 | } |
1278 | 1287 | ||
@@ -1288,32 +1297,32 @@ GCP_iterate_indirect_paths(struct CadetPeer *cp, | |||
1288 | * @return Number of iterated paths. | 1297 | * @return Number of iterated paths. |
1289 | */ | 1298 | */ |
1290 | unsigned int | 1299 | unsigned int |
1291 | GCP_iterate_paths_at(struct CadetPeer *cp, | 1300 | GCP_iterate_paths_at (struct CadetPeer *cp, |
1292 | unsigned int dist, | 1301 | unsigned int dist, |
1293 | GCP_PathIterator callback, | 1302 | GCP_PathIterator callback, |
1294 | void *callback_cls) | 1303 | void *callback_cls) |
1295 | { | 1304 | { |
1296 | unsigned int ret = 0; | 1305 | unsigned int ret = 0; |
1297 | 1306 | ||
1298 | if (dist >= cp->path_dll_length) | 1307 | if (dist >= cp->path_dll_length) |
1299 | { | 1308 | { |
1300 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1309 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1301 | "Asked to look for paths at distance %u, but maximum for me is < %u\n", | 1310 | "Asked to look for paths at distance %u, but maximum for me is < %u\n", |
1302 | dist, | 1311 | dist, |
1303 | cp->path_dll_length); | 1312 | cp->path_dll_length); |
1304 | return 0; | 1313 | return 0; |
1305 | } | 1314 | } |
1306 | for (struct CadetPeerPathEntry *pe = cp->path_heads[dist]; | 1315 | for (struct CadetPeerPathEntry *pe = cp->path_heads[dist]; |
1307 | NULL != pe; | 1316 | NULL != pe; |
1308 | pe = pe->next) | 1317 | pe = pe->next) |
1309 | { | 1318 | { |
1310 | if (GNUNET_NO == | 1319 | if (GNUNET_NO == |
1311 | callback(callback_cls, | 1320 | callback (callback_cls, |
1312 | pe->path, | 1321 | pe->path, |
1313 | dist)) | 1322 | dist)) |
1314 | return ret; | 1323 | return ret; |
1315 | ret++; | 1324 | ret++; |
1316 | } | 1325 | } |
1317 | return ret; | 1326 | return ret; |
1318 | } | 1327 | } |
1319 | 1328 | ||
@@ -1326,16 +1335,16 @@ GCP_iterate_paths_at(struct CadetPeer *cp, | |||
1326 | * @return Tunnel towards peer. | 1335 | * @return Tunnel towards peer. |
1327 | */ | 1336 | */ |
1328 | struct CadetTunnel * | 1337 | struct CadetTunnel * |
1329 | GCP_get_tunnel(struct CadetPeer *cp, | 1338 | GCP_get_tunnel (struct CadetPeer *cp, |
1330 | int create) | 1339 | int create) |
1331 | { | 1340 | { |
1332 | if (NULL == cp) | 1341 | if (NULL == cp) |
1333 | return NULL; | 1342 | return NULL; |
1334 | if ((NULL != cp->t) || | 1343 | if ((NULL != cp->t) || |
1335 | (GNUNET_NO == create)) | 1344 | (GNUNET_NO == create)) |
1336 | return cp->t; | 1345 | return cp->t; |
1337 | cp->t = GCT_create_tunnel(cp); | 1346 | cp->t = GCT_create_tunnel (cp); |
1338 | consider_peer_activate(cp); | 1347 | consider_peer_activate (cp); |
1339 | return cp->t; | 1348 | return cp->t; |
1340 | } | 1349 | } |
1341 | 1350 | ||
@@ -1347,7 +1356,7 @@ GCP_get_tunnel(struct CadetPeer *cp, | |||
1347 | * @param cls the `struct CadetPeer` where the offer completed | 1356 | * @param cls the `struct CadetPeer` where the offer completed |
1348 | */ | 1357 | */ |
1349 | static void | 1358 | static void |
1350 | hello_offer_done(void *cls) | 1359 | hello_offer_done (void *cls) |
1351 | { | 1360 | { |
1352 | struct CadetPeer *cp = cls; | 1361 | struct CadetPeer *cp = cls; |
1353 | 1362 | ||
@@ -1363,39 +1372,39 @@ hello_offer_done(void *cls) | |||
1363 | * @param hello the HELLO to remember | 1372 | * @param hello the HELLO to remember |
1364 | */ | 1373 | */ |
1365 | void | 1374 | void |
1366 | GCP_set_hello(struct CadetPeer *cp, | 1375 | GCP_set_hello (struct CadetPeer *cp, |
1367 | const struct GNUNET_HELLO_Message *hello) | 1376 | const struct GNUNET_HELLO_Message *hello) |
1368 | { | 1377 | { |
1369 | struct GNUNET_HELLO_Message *mrg; | 1378 | struct GNUNET_HELLO_Message *mrg; |
1370 | 1379 | ||
1371 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1380 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1372 | "Got %u byte HELLO for peer %s\n", | 1381 | "Got %u byte HELLO for peer %s\n", |
1373 | (unsigned int)GNUNET_HELLO_size(hello), | 1382 | (unsigned int) GNUNET_HELLO_size (hello), |
1374 | GCP_2s(cp)); | 1383 | GCP_2s (cp)); |
1375 | if (NULL != cp->hello_offer) | 1384 | if (NULL != cp->hello_offer) |
1376 | { | 1385 | { |
1377 | GNUNET_TRANSPORT_offer_hello_cancel(cp->hello_offer); | 1386 | GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer); |
1378 | cp->hello_offer = NULL; | 1387 | cp->hello_offer = NULL; |
1379 | } | 1388 | } |
1380 | if (NULL != cp->hello) | 1389 | if (NULL != cp->hello) |
1381 | { | 1390 | { |
1382 | mrg = GNUNET_HELLO_merge(hello, | 1391 | mrg = GNUNET_HELLO_merge (hello, |
1383 | cp->hello); | 1392 | cp->hello); |
1384 | GNUNET_free(cp->hello); | 1393 | GNUNET_free (cp->hello); |
1385 | cp->hello = mrg; | 1394 | cp->hello = mrg; |
1386 | } | 1395 | } |
1387 | else | 1396 | else |
1388 | { | 1397 | { |
1389 | cp->hello = GNUNET_memdup(hello, | 1398 | cp->hello = GNUNET_memdup (hello, |
1390 | GNUNET_HELLO_size(hello)); | 1399 | GNUNET_HELLO_size (hello)); |
1391 | } | 1400 | } |
1392 | cp->hello_offer | 1401 | cp->hello_offer |
1393 | = GNUNET_TRANSPORT_offer_hello(cfg, | 1402 | = GNUNET_TRANSPORT_offer_hello (cfg, |
1394 | GNUNET_HELLO_get_header(cp->hello), | 1403 | GNUNET_HELLO_get_header (cp->hello), |
1395 | &hello_offer_done, | 1404 | &hello_offer_done, |
1396 | cp); | 1405 | cp); |
1397 | /* New HELLO means cp's destruction time may change... */ | 1406 | /* New HELLO means cp's destruction time may change... */ |
1398 | consider_peer_destroy(cp); | 1407 | consider_peer_destroy (cp); |
1399 | } | 1408 | } |
1400 | 1409 | ||
1401 | 1410 | ||
@@ -1407,16 +1416,16 @@ GCP_set_hello(struct CadetPeer *cp, | |||
1407 | * @param t the dead tunnel | 1416 | * @param t the dead tunnel |
1408 | */ | 1417 | */ |
1409 | void | 1418 | void |
1410 | GCP_drop_tunnel(struct CadetPeer *cp, | 1419 | GCP_drop_tunnel (struct CadetPeer *cp, |
1411 | struct CadetTunnel *t) | 1420 | struct CadetTunnel *t) |
1412 | { | 1421 | { |
1413 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1422 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1414 | "Dropping tunnel %s to peer %s\n", | 1423 | "Dropping tunnel %s to peer %s\n", |
1415 | GCT_2s(t), | 1424 | GCT_2s (t), |
1416 | GCP_2s(cp)); | 1425 | GCP_2s (cp)); |
1417 | GNUNET_assert(cp->t == t); | 1426 | GNUNET_assert (cp->t == t); |
1418 | cp->t = NULL; | 1427 | cp->t = NULL; |
1419 | consider_peer_destroy(cp); | 1428 | consider_peer_destroy (cp); |
1420 | } | 1429 | } |
1421 | 1430 | ||
1422 | 1431 | ||
@@ -1427,7 +1436,7 @@ GCP_drop_tunnel(struct CadetPeer *cp, | |||
1427 | * @return #GNUNET_YES if @a cp has a core-level connection | 1436 | * @return #GNUNET_YES if @a cp has a core-level connection |
1428 | */ | 1437 | */ |
1429 | int | 1438 | int |
1430 | GCP_has_core_connection(struct CadetPeer *cp) | 1439 | GCP_has_core_connection (struct CadetPeer *cp) |
1431 | { | 1440 | { |
1432 | return (NULL != cp->core_mq) ? GNUNET_YES : GNUNET_NO; | 1441 | return (NULL != cp->core_mq) ? GNUNET_YES : GNUNET_NO; |
1433 | } | 1442 | } |
@@ -1442,26 +1451,26 @@ GCP_has_core_connection(struct CadetPeer *cp) | |||
1442 | * @return handle to cancel request | 1451 | * @return handle to cancel request |
1443 | */ | 1452 | */ |
1444 | struct GCP_MessageQueueManager * | 1453 | struct GCP_MessageQueueManager * |
1445 | GCP_request_mq(struct CadetPeer *cp, | 1454 | GCP_request_mq (struct CadetPeer *cp, |
1446 | GCP_MessageQueueNotificationCallback cb, | 1455 | GCP_MessageQueueNotificationCallback cb, |
1447 | void *cb_cls) | 1456 | void *cb_cls) |
1448 | { | 1457 | { |
1449 | struct GCP_MessageQueueManager *mqm; | 1458 | struct GCP_MessageQueueManager *mqm; |
1450 | 1459 | ||
1451 | mqm = GNUNET_new(struct GCP_MessageQueueManager); | 1460 | mqm = GNUNET_new (struct GCP_MessageQueueManager); |
1452 | mqm->cb = cb; | 1461 | mqm->cb = cb; |
1453 | mqm->cb_cls = cb_cls; | 1462 | mqm->cb_cls = cb_cls; |
1454 | mqm->cp = cp; | 1463 | mqm->cp = cp; |
1455 | GNUNET_CONTAINER_DLL_insert(cp->mqm_head, | 1464 | GNUNET_CONTAINER_DLL_insert (cp->mqm_head, |
1456 | cp->mqm_tail, | 1465 | cp->mqm_tail, |
1457 | mqm); | 1466 | mqm); |
1458 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1467 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1459 | "Creating MQM %p for peer %s\n", | 1468 | "Creating MQM %p for peer %s\n", |
1460 | mqm, | 1469 | mqm, |
1461 | GCP_2s(cp)); | 1470 | GCP_2s (cp)); |
1462 | if (NULL != cp->core_mq) | 1471 | if (NULL != cp->core_mq) |
1463 | cb(cb_cls, | 1472 | cb (cb_cls, |
1464 | GNUNET_YES); | 1473 | GNUNET_YES); |
1465 | return mqm; | 1474 | return mqm; |
1466 | } | 1475 | } |
1467 | 1476 | ||
@@ -1473,39 +1482,39 @@ GCP_request_mq(struct CadetPeer *cp, | |||
1473 | * @param last_env final message to transmit, or NULL | 1482 | * @param last_env final message to transmit, or NULL |
1474 | */ | 1483 | */ |
1475 | void | 1484 | void |
1476 | GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm, | 1485 | GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm, |
1477 | struct GNUNET_MQ_Envelope *last_env) | 1486 | struct GNUNET_MQ_Envelope *last_env) |
1478 | { | 1487 | { |
1479 | struct CadetPeer *cp = mqm->cp; | 1488 | struct CadetPeer *cp = mqm->cp; |
1480 | 1489 | ||
1481 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1490 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1482 | "Destroying MQM %p for peer %s%s\n", | 1491 | "Destroying MQM %p for peer %s%s\n", |
1483 | mqm, | 1492 | mqm, |
1484 | GCP_2s(cp), | 1493 | GCP_2s (cp), |
1485 | (NULL == last_env) ? "" : " with last ditch transmission"); | 1494 | (NULL == last_env) ? "" : " with last ditch transmission"); |
1486 | if (NULL != mqm->env) | 1495 | if (NULL != mqm->env) |
1487 | GNUNET_MQ_discard(mqm->env); | 1496 | GNUNET_MQ_discard (mqm->env); |
1488 | if (NULL != last_env) | 1497 | if (NULL != last_env) |
1498 | { | ||
1499 | if (NULL != cp->core_mq) | ||
1489 | { | 1500 | { |
1490 | if (NULL != cp->core_mq) | 1501 | GNUNET_MQ_notify_sent (last_env, |
1491 | { | 1502 | &mqm_send_done, |
1492 | GNUNET_MQ_notify_sent(last_env, | 1503 | cp); |
1493 | &mqm_send_done, | 1504 | GNUNET_MQ_send (cp->core_mq, |
1494 | cp); | 1505 | last_env); |
1495 | GNUNET_MQ_send(cp->core_mq, | ||
1496 | last_env); | ||
1497 | } | ||
1498 | else | ||
1499 | { | ||
1500 | GNUNET_MQ_discard(last_env); | ||
1501 | } | ||
1502 | } | 1506 | } |
1507 | else | ||
1508 | { | ||
1509 | GNUNET_MQ_discard (last_env); | ||
1510 | } | ||
1511 | } | ||
1503 | if (cp->mqm_ready_ptr == mqm) | 1512 | if (cp->mqm_ready_ptr == mqm) |
1504 | cp->mqm_ready_ptr = mqm->next; | 1513 | cp->mqm_ready_ptr = mqm->next; |
1505 | GNUNET_CONTAINER_DLL_remove(cp->mqm_head, | 1514 | GNUNET_CONTAINER_DLL_remove (cp->mqm_head, |
1506 | cp->mqm_tail, | 1515 | cp->mqm_tail, |
1507 | mqm); | 1516 | mqm); |
1508 | GNUNET_free(mqm); | 1517 | GNUNET_free (mqm); |
1509 | } | 1518 | } |
1510 | 1519 | ||
1511 | 1520 | ||
@@ -1519,27 +1528,27 @@ GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm, | |||
1519 | * @param env envelope with the message to send | 1528 | * @param env envelope with the message to send |
1520 | */ | 1529 | */ |
1521 | void | 1530 | void |
1522 | GCP_send_ooo(struct CadetPeer *cp, | 1531 | GCP_send_ooo (struct CadetPeer *cp, |
1523 | struct GNUNET_MQ_Envelope *env) | 1532 | struct GNUNET_MQ_Envelope *env) |
1524 | { | 1533 | { |
1525 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1534 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1526 | "Sending message to %s out of management\n", | 1535 | "Sending message to %s out of management\n", |
1527 | GCP_2s(cp)); | 1536 | GCP_2s (cp)); |
1528 | if (NULL == cp->core_mq) | 1537 | if (NULL == cp->core_mq) |
1529 | { | 1538 | { |
1530 | GNUNET_MQ_discard(env); | 1539 | GNUNET_MQ_discard (env); |
1531 | return; | 1540 | return; |
1532 | } | 1541 | } |
1533 | if (GNUNET_MQ_get_length(cp->core_mq) > MAX_OOO_QUEUE_SIZE) | 1542 | if (GNUNET_MQ_get_length (cp->core_mq) > MAX_OOO_QUEUE_SIZE) |
1534 | { | 1543 | { |
1535 | GNUNET_MQ_discard(env); | 1544 | GNUNET_MQ_discard (env); |
1536 | return; | 1545 | return; |
1537 | } | 1546 | } |
1538 | GNUNET_MQ_notify_sent(env, | 1547 | GNUNET_MQ_notify_sent (env, |
1539 | &mqm_send_done, | 1548 | &mqm_send_done, |
1540 | cp); | 1549 | cp); |
1541 | GNUNET_MQ_send(cp->core_mq, | 1550 | GNUNET_MQ_send (cp->core_mq, |
1542 | env); | 1551 | env); |
1543 | } | 1552 | } |
1544 | 1553 | ||
1545 | 1554 | ||