From 755b5bb632de94de0e6b0e55212fbcce7b6c719c Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 9 Nov 2012 12:34:17 +0000 Subject: adopting to new transport API --- src/testbed/gnunet-service-testbed.c | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/testbed/gnunet-service-testbed.c') diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index c9b7c930a..2f606928a 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -2861,6 +2861,59 @@ overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer, } +/** + * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to + * peer 1. + * + * @param cls the OverlayConnectContext + * @param tc the TaskContext from scheduler + */ +static void +send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); + + +/** + * Task that is run when hello has been sent + * + * @param cls the overlay connect context + * @param tc the scheduler task context; if tc->reason = + * GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if + * GNUNET_SCHEDULER_REASON_READ_READY is succeeded + */ +//static FIXME: uncomment when using +void +occ_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct OverlayConnectContext *occ = cls; + int ret; + + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task); + if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason) + { + occ->send_hello_task = + GNUNET_SCHEDULER_add_delayed + (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, + 100 + GNUNET_CRYPTO_random_u32 + (GNUNET_CRYPTO_QUALITY_WEAK, 500)), + &send_hello, occ); + return; + } + if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) + return; + ret = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity); + if (GNUNET_OK == ret) + return; + if (GNUNET_SYSERR == ret) + GNUNET_break (0); + occ->send_hello_task = + GNUNET_SCHEDULER_add_delayed + (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, + 100 + GNUNET_CRYPTO_random_u32 + (GNUNET_CRYPTO_QUALITY_WEAK, 500)), + &send_hello, occ); +} + + /** * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to * peer 1. @@ -2903,6 +2956,13 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { LOG_DEBUG ("Offering HELLO of %s to %s\n", GNUNET_i2s (&occ->peer_identity), other_peer_str); + /* FIXME: To be replaced by */ + /* occ->offer_hello_handle = GNUNET_TRANSPORT_offer_hello (occ->p2th, */ + /* occ->hello, */ + /* occ_hello_sent_cb, */ + /* occ); */ + + /* FIXME: once offer_hello offers a handle to cancel remove the following lines */ GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL); GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity); occ->send_hello_task = -- cgit v1.2.3