diff options
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 95 |
1 files changed, 84 insertions, 11 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 62163ca36..cf1e3ce48 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -642,6 +642,16 @@ struct RequestOverlayConnectContext | |||
642 | struct GNUNET_MessageHeader *hello; | 642 | struct GNUNET_MessageHeader *hello; |
643 | 643 | ||
644 | /** | 644 | /** |
645 | * The handle for offering HELLO | ||
646 | */ | ||
647 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; | ||
648 | |||
649 | /** | ||
650 | * The handle for transport try connect | ||
651 | */ | ||
652 | struct GNUNET_TRANSPORT_TryConnectHandle *tch; | ||
653 | |||
654 | /** | ||
645 | * The peer identity of peer A | 655 | * The peer identity of peer A |
646 | */ | 656 | */ |
647 | struct GNUNET_PeerIdentity a_id; | 657 | struct GNUNET_PeerIdentity a_id; |
@@ -2932,10 +2942,7 @@ occ_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2932 | goto schedule_send_hello; | 2942 | goto schedule_send_hello; |
2933 | } | 2943 | } |
2934 | if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) | 2944 | if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) |
2935 | { | ||
2936 | GNUNET_break (0); | ||
2937 | return; | 2945 | return; |
2938 | } | ||
2939 | GNUNET_free_non_null (occ->emsg); | 2946 | GNUNET_free_non_null (occ->emsg); |
2940 | occ->emsg = GNUNET_strdup ("Timeout while try connect\n"); | 2947 | occ->emsg = GNUNET_strdup ("Timeout while try connect\n"); |
2941 | occ->tch = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, | 2948 | occ->tch = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, |
@@ -3494,6 +3501,10 @@ cleanup_rocc (struct RequestOverlayConnectContext *rocc) | |||
3494 | if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id) | 3501 | if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id) |
3495 | GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id); | 3502 | GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id); |
3496 | GNUNET_TRANSPORT_disconnect (rocc->th); | 3503 | GNUNET_TRANSPORT_disconnect (rocc->th); |
3504 | if (NULL != rocc->tch) | ||
3505 | GNUNET_TRANSPORT_try_connect_cancel (rocc->tch); | ||
3506 | if (NULL != rocc->ohh) | ||
3507 | GNUNET_TRANSPORT_offer_hello_cancel (rocc->ohh); | ||
3497 | GNUNET_free_non_null (rocc->hello); | 3508 | GNUNET_free_non_null (rocc->hello); |
3498 | GNUNET_CONTAINER_DLL_remove (roccq_head, roccq_tail, rocc); | 3509 | GNUNET_CONTAINER_DLL_remove (roccq_head, roccq_tail, rocc); |
3499 | GNUNET_free (rocc); | 3510 | GNUNET_free (rocc); |
@@ -3541,6 +3552,67 @@ transport_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer, | |||
3541 | 3552 | ||
3542 | 3553 | ||
3543 | /** | 3554 | /** |
3555 | * Callback to be called with result of the try connect request. | ||
3556 | * | ||
3557 | * @param cls the overlay connect context | ||
3558 | * @param result GNUNET_OK if message was transmitted to transport service | ||
3559 | * GNUNET_SYSERR if message was not transmitted to transport service | ||
3560 | */ | ||
3561 | static void | ||
3562 | rocc_try_connect_cb (void *cls, const int result) | ||
3563 | { | ||
3564 | struct RequestOverlayConnectContext *rocc = cls; | ||
3565 | |||
3566 | rocc->tch = NULL; | ||
3567 | rocc->tch = GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id, | ||
3568 | &rocc_try_connect_cb, rocc); | ||
3569 | } | ||
3570 | |||
3571 | |||
3572 | /** | ||
3573 | * Task to offer the HELLO message to the peer and ask it to connect to the peer | ||
3574 | * whose identity is in RequestOverlayConnectContext | ||
3575 | * | ||
3576 | * @param cls the RequestOverlayConnectContext | ||
3577 | * @param tc the TaskContext from scheduler | ||
3578 | */ | ||
3579 | static void | ||
3580 | attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
3581 | |||
3582 | |||
3583 | /** | ||
3584 | * Task that is run when hello has been sent | ||
3585 | * | ||
3586 | * @param cls the overlay connect context | ||
3587 | * @param tc the scheduler task context; if tc->reason = | ||
3588 | * GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if | ||
3589 | * GNUNET_SCHEDULER_REASON_READ_READY is succeeded | ||
3590 | */ | ||
3591 | static void | ||
3592 | rocc_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3593 | { | ||
3594 | struct RequestOverlayConnectContext *rocc = cls; | ||
3595 | |||
3596 | rocc->ohh = NULL; | ||
3597 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rocc->attempt_connect_task_id); | ||
3598 | if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason) | ||
3599 | goto schedule_attempt_connect; | ||
3600 | if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) | ||
3601 | return; | ||
3602 | rocc->tch = GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id, | ||
3603 | &rocc_try_connect_cb, rocc); | ||
3604 | if (NULL != rocc->tch) | ||
3605 | return; | ||
3606 | GNUNET_break (0); | ||
3607 | |||
3608 | schedule_attempt_connect: | ||
3609 | rocc->attempt_connect_task_id = | ||
3610 | GNUNET_SCHEDULER_add_now (&attempt_connect_task, | ||
3611 | rocc); | ||
3612 | } | ||
3613 | |||
3614 | |||
3615 | /** | ||
3544 | * Task to offer the HELLO message to the peer and ask it to connect to the peer | 3616 | * Task to offer the HELLO message to the peer and ask it to connect to the peer |
3545 | * whose identity is in RequestOverlayConnectContext | 3617 | * whose identity is in RequestOverlayConnectContext |
3546 | * | 3618 | * |
@@ -3553,14 +3625,15 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3553 | struct RequestOverlayConnectContext *rocc = cls; | 3625 | struct RequestOverlayConnectContext *rocc = cls; |
3554 | 3626 | ||
3555 | rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK; | 3627 | rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK; |
3556 | GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, NULL, NULL); | 3628 | rocc->ohh = GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, |
3557 | GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id, NULL, NULL); /*FIXME TRY_CONNECT change */ | 3629 | rocc_hello_sent_cb, rocc); |
3558 | rocc->attempt_connect_task_id = | 3630 | if (NULL == rocc->ohh) |
3559 | GNUNET_SCHEDULER_add_delayed | 3631 | rocc->attempt_connect_task_id = |
3560 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 3632 | GNUNET_SCHEDULER_add_delayed |
3561 | 100 + GNUNET_CRYPTO_random_u32 | 3633 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
3562 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), | 3634 | 100 + GNUNET_CRYPTO_random_u32 |
3563 | &attempt_connect_task, rocc); | 3635 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), |
3636 | &attempt_connect_task, rocc); | ||
3564 | } | 3637 | } |
3565 | 3638 | ||
3566 | 3639 | ||