aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-11-14 15:52:09 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-11-14 15:52:09 +0000
commit958367dc3eb8bcef571c9f05ace9dbfcaee037e1 (patch)
treec583663efa9a064cea28f3634684bbc93ea63587
parent7c075be5f2a92066fb866dff76bb8b0e2cabcbc5 (diff)
downloadgnunet-958367dc3eb8bcef571c9f05ace9dbfcaee037e1.tar.gz
gnunet-958367dc3eb8bcef571c9f05ace9dbfcaee037e1.zip
- try connect as task in rocc
-rw-r--r--src/testbed/gnunet-service-testbed.c63
1 files changed, 20 insertions, 43 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 70c61cfdc..9ffdf7812 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -660,11 +660,6 @@ struct RequestOverlayConnectContext
660 struct RequestOverlayConnectContext *prev; 660 struct RequestOverlayConnectContext *prev;
661 661
662 /** 662 /**
663 * The transport handle of peer B
664 */
665 struct GNUNET_TRANSPORT_Handle *th;
666
667 /**
668 * The peer handle of peer B 663 * The peer handle of peer B
669 */ 664 */
670 struct Peer *peer; 665 struct Peer *peer;
@@ -680,9 +675,9 @@ struct RequestOverlayConnectContext
680 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; 675 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
681 676
682 /** 677 /**
683 * The handle for transport try connect 678 * The transport try connect context
684 */ 679 */
685 struct GNUNET_TRANSPORT_TryConnectHandle *tch; 680 struct TryConnectContext tcc;
686 681
687 /** 682 /**
688 * The peer identity of peer A 683 * The peer identity of peer A
@@ -3556,11 +3551,13 @@ cleanup_rocc (struct RequestOverlayConnectContext *rocc)
3556 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id); 3551 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
3557 if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id) 3552 if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id)
3558 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id); 3553 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id);
3559 if (NULL != rocc->tch)
3560 GNUNET_TRANSPORT_try_connect_cancel (rocc->tch);
3561 if (NULL != rocc->ohh) 3554 if (NULL != rocc->ohh)
3562 GNUNET_TRANSPORT_offer_hello_cancel (rocc->ohh); 3555 GNUNET_TRANSPORT_offer_hello_cancel (rocc->ohh);
3563 GNUNET_TRANSPORT_disconnect (rocc->th); 3556 if (NULL != rocc->tcc.tch)
3557 GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch);
3558 if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task)
3559 GNUNET_SCHEDULER_cancel (rocc->tcc.task);
3560 GNUNET_TRANSPORT_disconnect (rocc->tcc.th);
3564 rocc->peer->reference_cnt--; 3561 rocc->peer->reference_cnt--;
3565 if ((GNUNET_YES == rocc->peer->destroy_flag) 3562 if ((GNUNET_YES == rocc->peer->destroy_flag)
3566 && (0 == rocc->peer->reference_cnt)) 3563 && (0 == rocc->peer->reference_cnt))
@@ -3612,24 +3609,6 @@ transport_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
3612 3609
3613 3610
3614/** 3611/**
3615 * Callback to be called with result of the try connect request.
3616 *
3617 * @param cls the overlay connect context
3618 * @param result GNUNET_OK if message was transmitted to transport service
3619 * GNUNET_SYSERR if message was not transmitted to transport service
3620 */
3621static void
3622rocc_try_connect_cb (void *cls, const int result)
3623{
3624 struct RequestOverlayConnectContext *rocc = cls;
3625
3626 rocc->tch = NULL;
3627 rocc->tch = GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id,
3628 &rocc_try_connect_cb, rocc);
3629}
3630
3631
3632/**
3633 * Task to offer the HELLO message to the peer and ask it to connect to the peer 3612 * Task to offer the HELLO message to the peer and ask it to connect to the peer
3634 * whose identity is in RequestOverlayConnectContext 3613 * whose identity is in RequestOverlayConnectContext
3635 * 3614 *
@@ -3656,19 +3635,16 @@ rocc_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3656 rocc->ohh = NULL; 3635 rocc->ohh = NULL;
3657 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rocc->attempt_connect_task_id); 3636 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rocc->attempt_connect_task_id);
3658 if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason) 3637 if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
3659 goto schedule_attempt_connect; 3638 {
3660 if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) 3639 GNUNET_break (0);
3640 rocc->attempt_connect_task_id =
3641 GNUNET_SCHEDULER_add_now (&attempt_connect_task,
3642 rocc);
3661 return; 3643 return;
3662 rocc->tch = GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id, 3644 }
3663 &rocc_try_connect_cb, rocc); 3645 if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason)
3664 if (NULL != rocc->tch)
3665 return; 3646 return;
3666 GNUNET_break (0); 3647 rocc->tcc.task = GNUNET_SCHEDULER_add_now (&try_connect_task, &rocc->tcc);
3667
3668 schedule_attempt_connect:
3669 rocc->attempt_connect_task_id =
3670 GNUNET_SCHEDULER_add_now (&attempt_connect_task,
3671 rocc);
3672} 3648}
3673 3649
3674 3650
@@ -3685,7 +3661,7 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3685 struct RequestOverlayConnectContext *rocc = cls; 3661 struct RequestOverlayConnectContext *rocc = cls;
3686 3662
3687 rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK; 3663 rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK;
3688 rocc->ohh = GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, 3664 rocc->ohh = GNUNET_TRANSPORT_offer_hello (rocc->tcc.th, rocc->hello,
3689 rocc_hello_sent_cb, rocc); 3665 rocc_hello_sent_cb, rocc);
3690 if (NULL == rocc->ohh) 3666 if (NULL == rocc->ohh)
3691 rocc->attempt_connect_task_id = 3667 rocc->attempt_connect_task_id =
@@ -3757,9 +3733,9 @@ handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
3757 GNUNET_CONTAINER_DLL_insert_tail (roccq_head, roccq_tail, rocc); 3733 GNUNET_CONTAINER_DLL_insert_tail (roccq_head, roccq_tail, rocc);
3758 rocc->peer = peer; 3734 rocc->peer = peer;
3759 rocc->peer->reference_cnt++; 3735 rocc->peer->reference_cnt++;
3760 rocc->th = GNUNET_TRANSPORT_connect (rocc->peer->details.local.cfg, NULL, rocc, 3736 rocc->tcc.th = GNUNET_TRANSPORT_connect (rocc->peer->details.local.cfg, NULL, rocc,
3761 NULL, &transport_connect_notify, NULL); 3737 NULL, &transport_connect_notify, NULL);
3762 if (NULL == rocc->th) 3738 if (NULL == rocc->tcc.th)
3763 { 3739 {
3764 GNUNET_break (0); 3740 GNUNET_break (0);
3765 GNUNET_free (rocc); 3741 GNUNET_free (rocc);
@@ -3768,6 +3744,7 @@ handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
3768 } 3744 }
3769 memcpy (&rocc->a_id, &msg->peer_identity, 3745 memcpy (&rocc->a_id, &msg->peer_identity,
3770 sizeof (struct GNUNET_PeerIdentity)); 3746 sizeof (struct GNUNET_PeerIdentity));
3747 rocc->tcc.pid = &rocc->a_id;
3771 rocc->hello = GNUNET_malloc (hsize); 3748 rocc->hello = GNUNET_malloc (hsize);
3772 memcpy (rocc->hello, msg->hello, hsize); 3749 memcpy (rocc->hello, msg->hello, hsize);
3773 rocc->attempt_connect_task_id = 3750 rocc->attempt_connect_task_id =