| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2013-2017, Regents of the University of California. |
| * |
| * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
| * |
| * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, either |
| * version 3 of the License, or (at your option) any later version. |
| * |
| * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received copies of the GNU General Public License along with |
| * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| * |
| * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
| */ |
| |
| #ifndef CHRONOSHARE_SRC_FETCHER_HPP |
| #define CHRONOSHARE_SRC_FETCHER_HPP |
| |
| #include "core/chronoshare-common.hpp" |
| |
| #include <ndn-cxx/face.hpp> |
| |
| #include <set> |
| #include <thread> |
| #include <mutex> |
| #include <boost/intrusive/list.hpp> |
| |
| namespace ndn { |
| namespace chronoshare { |
| |
| class FetchManager; |
| |
| class Fetcher |
| { |
| public: |
| typedef std::function<void(Name& deviceName, Name& baseName, uint64_t seq, shared_ptr<Data> data)> SegmentCallback; |
| typedef std::function<void(Name& deviceName, Name& baseName)> FinishCallback; |
| typedef std::function<void(Fetcher&, const Name& deviceName, const Name& baseName)> OnFetchCompleteCallback; |
| typedef std::function<void(Fetcher&)> OnFetchFailedCallback; |
| |
| Fetcher(Face& face, |
| const SegmentCallback& segmentCallback, // callback passed by caller of FetchManager |
| const FinishCallback& finishCallback, // callback passed by caller of FetchManager |
| const OnFetchCompleteCallback& onFetchComplete, |
| const OnFetchFailedCallback& onFetchFailed, // callbacks provided by FetchManager |
| const Name& deviceName, const Name& name, int64_t minSeqNo, int64_t maxSeqNo, |
| time::milliseconds timeout = time::seconds(30), // this time is not precise, but sets min bound |
| // actual time depends on how fast Interests timeout |
| const Name& forwardingHint = Name()); |
| virtual ~Fetcher(); |
| |
| bool |
| IsActive() const; |
| |
| bool |
| IsTimedWait() const |
| { |
| return m_timedwait; |
| } |
| |
| void |
| RestartPipeline(); |
| |
| void |
| SetForwardingHint(const Name& forwardingHint); |
| |
| const Name& |
| GetForwardingHint() const |
| { |
| return m_forwardingHint; |
| } |
| |
| const Name& |
| GetName() const |
| { |
| return m_name; |
| } |
| |
| const Name& |
| GetDeviceName() const |
| { |
| return m_deviceName; |
| } |
| |
| time::seconds |
| GetRetryPause() const |
| { |
| return m_retryPause; |
| } |
| |
| void |
| SetRetryPause(time::seconds pause) |
| { |
| m_retryPause = pause; |
| } |
| |
| const time::steady_clock::TimePoint& |
| GetNextScheduledRetry() const |
| { |
| return m_nextScheduledRetry; |
| } |
| |
| void |
| SetNextScheduledRetry(const time::steady_clock::TimePoint& nextScheduledRetry) |
| { |
| m_nextScheduledRetry = nextScheduledRetry; |
| } |
| |
| private: |
| void |
| FillPipeline(); |
| |
| void |
| OnData(uint64_t seqno, const Interest& interest, Data& data); |
| |
| void |
| OnTimeout(uint64_t seqno, const Interest& interest); |
| |
| public: |
| boost::intrusive::list_member_hook<> m_managerListHook; |
| |
| private: |
| Face& m_face; |
| |
| SegmentCallback m_segmentCallback; |
| OnFetchCompleteCallback m_onFetchComplete; |
| OnFetchFailedCallback m_onFetchFailed; |
| |
| FinishCallback m_finishCallback; |
| |
| bool m_active; |
| bool m_timedwait; |
| |
| Name m_name; |
| Name m_deviceName; |
| Name m_forwardingHint; |
| |
| time::milliseconds m_maximumNoActivityPeriod; |
| |
| int64_t m_minSendSeqNo; |
| int64_t m_maxInOrderRecvSeqNo; |
| std::set<int64_t> m_outOfOrderRecvSeqNo; |
| std::set<int64_t> m_inActivePipeline; |
| |
| // int64_t m_minSeqNo; |
| int64_t m_maxSeqNo; |
| |
| uint32_t m_pipeline; |
| uint32_t m_activePipeline; |
| // double m_rto; |
| // double m_maxRto; |
| bool m_slowStart; |
| uint32_t m_threshold; |
| uint32_t m_roundCount; |
| |
| time::steady_clock::TimePoint m_lastPositiveActivity; |
| |
| time::seconds m_retryPause; // pause to stop trying to fetch(for fetch-manager) |
| time::steady_clock::TimePoint m_nextScheduledRetry; |
| |
| std::mutex m_seqNoMutex; |
| |
| boost::asio::io_service& m_ioService; |
| }; |
| |
| typedef shared_ptr<Fetcher> FetcherPtr; |
| |
| inline bool |
| Fetcher::IsActive() const |
| { |
| return m_active; |
| } |
| |
| } // namespace chronoshare |
| } // namespace ndn |
| |
| #endif // CHRONOSHARE_SRC_FETCHER_HPP |