From 584e120f3c0f6f3320ed5c8acdcb71a87498d1d9 Mon Sep 17 00:00:00 2001 From: Ashlesh Gawande Date: Sun, 19 May 2019 16:15:33 -0700 Subject: [PATCH] PSync: use interest lifetime as initialRto in SegmentFetcher refs: #4945 Change-Id: If9e3d268da3dbffda3f4a7d67039413954628d2b --- PSync/consumer.cpp | 4 ++++ PSync/full-producer.cpp | 13 +++++-------- PSync/full-producer.hpp | 3 +-- tests/test-consumer.cpp | 24 ++++++++++++++++++++++++ tests/test-full-producer.cpp | 15 +++++++++++++++ 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/PSync/consumer.cpp b/PSync/consumer.cpp index 24483a7..ce4a65d 100644 --- a/PSync/consumer.cpp +++ b/PSync/consumer.cpp @@ -68,6 +68,8 @@ Consumer::addSubscription(const ndn::Name& prefix) void Consumer::stop() { + m_scheduler.cancelAllEvents(); + if (m_syncFetcher) { m_syncFetcher->stop(); m_syncFetcher.reset(); @@ -93,6 +95,7 @@ Consumer::sendHelloInterest() SegmentFetcher::Options options; options.interestLifetime = m_helloInterestLifetime; options.maxTimeout = m_helloInterestLifetime; + options.rttOptions.initialRto = m_syncInterestLifetime; m_helloFetcher = SegmentFetcher::start(m_face, helloInterest, ndn::security::v2::getAcceptAllValidator(), options); @@ -179,6 +182,7 @@ Consumer::sendSyncInterest() SegmentFetcher::Options options; options.interestLifetime = m_syncInterestLifetime; options.maxTimeout = m_syncInterestLifetime;; + options.rttOptions.initialRto = m_syncInterestLifetime; m_syncFetcher = SegmentFetcher::start(m_face, syncInterest, ndn::security::v2::getAcceptAllValidator(), options); diff --git a/PSync/full-producer.cpp b/PSync/full-producer.cpp index a7a0b24..c31504c 100644 --- a/PSync/full-producer.cpp +++ b/PSync/full-producer.cpp @@ -107,6 +107,7 @@ FullProducer::sendSyncInterest() SegmentFetcher::Options options; options.interestLifetime = m_syncInterestLifetime; options.maxTimeout = m_syncInterestLifetime; + options.rttOptions.initialRto = m_syncInterestLifetime; m_fetcher = SegmentFetcher::start(m_face, syncInterest, ndn::security::v2::getAcceptAllValidator(), options); @@ -341,14 +342,10 @@ FullProducer::isFutureHash(const ndn::Name& prefix, const std::set& ne void FullProducer::deletePendingInterests(const ndn::Name& interestName) { - for (auto it = m_pendingEntries.begin(); it != m_pendingEntries.end();) { - if (it->first == interestName) { - NDN_LOG_TRACE("Delete pending interest: " << interestName); - it = m_pendingEntries.erase(it); - } - else { - ++it; - } + auto it = m_pendingEntries.find(interestName); + if (it != m_pendingEntries.end()) { + NDN_LOG_TRACE("Delete pending interest: " << interestName); + it = m_pendingEntries.erase(it); } } diff --git a/PSync/full-producer.hpp b/PSync/full-producer.hpp index f51ea7d..82b7be6 100644 --- a/PSync/full-producer.hpp +++ b/PSync/full-producer.hpp @@ -97,7 +97,7 @@ public: void publishName(const ndn::Name& prefix, ndn::optional seq = ndn::nullopt); -private: +PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE: /** * @brief Send sync interest for full synchronization * @@ -108,7 +108,6 @@ private: void sendSyncInterest(); -PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE: /** * @brief Process sync interest from other parties * diff --git a/tests/test-consumer.cpp b/tests/test-consumer.cpp index d1e6115..67b524c 100644 --- a/tests/test-consumer.cpp +++ b/tests/test-consumer.cpp @@ -18,6 +18,7 @@ **/ #include "PSync/consumer.hpp" +#include "unit-test-time-fixture.hpp" #include #include @@ -56,6 +57,29 @@ BOOST_AUTO_TEST_CASE(AddSubscription) BOOST_CHECK(!consumer.addSubscription(subscription)); } +BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, ndn::tests::UnitTestTimeFixture) +{ + util::DummyClientFace face(io, {true, true}); + Consumer consumer(Name("/psync"), face, + [] (const vector&) {}, + [] (const vector&) {}, + 40, 0.001, + ndn::time::milliseconds(4000), + ndn::time::milliseconds(4000)); + + consumer.sendHelloInterest(); + advanceClocks(ndn::time::milliseconds(4000)); + BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); + face.sentInterests.clear(); + consumer.stop(); + + consumer.m_iblt = ndn::Name("test"); + consumer.sendSyncInterest(); + advanceClocks(ndn::time::milliseconds(4000)); + BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); + consumer.stop(); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace psync \ No newline at end of file diff --git a/tests/test-full-producer.cpp b/tests/test-full-producer.cpp index 8190446..2bd7db4 100644 --- a/tests/test-full-producer.cpp +++ b/tests/test-full-producer.cpp @@ -18,6 +18,7 @@ **/ #include "PSync/full-producer.hpp" +#include "unit-test-time-fixture.hpp" #include #include @@ -50,6 +51,20 @@ BOOST_AUTO_TEST_CASE(OnInterest) BOOST_REQUIRE_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName))); } +BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, ndn::tests::UnitTestTimeFixture) +{ + Name syncPrefix("/psync"), userNode("/testUser"); + util::DummyClientFace face(io, {true, true}); + + FullProducer node(40, face, syncPrefix, userNode, nullptr, ndn::time::milliseconds(8000)); + advanceClocks(ndn::time::milliseconds(10)); + face.sentInterests.clear(); + + // full sync sends the next one in interest lifetime / 2 +- jitter + advanceClocks(ndn::time::milliseconds(6000)); + BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace psync \ No newline at end of file