Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 3 | * Copyright (c) 2016-2024, Regents of the University of California, |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 6 | * |
| 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 9 | * |
| 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 22 | * |
| 23 | * @author Wentao Shang |
| 24 | * @author Steve DiBenedetto |
| 25 | * @author Andrea Tosatto |
| 26 | * @author Davide Pesavento |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 27 | * @author Chavoosh Ghasemi |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 28 | */ |
| 29 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 30 | #ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_HPP |
| 31 | #define NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_HPP |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 32 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 33 | #include "pipeline-interests.hpp" |
| 34 | |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 35 | #include <vector> |
| 36 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 37 | namespace ndn::chunks { |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 38 | |
| 39 | class DataFetcher; |
| 40 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 41 | /** |
| 42 | * @brief Service for retrieving Data via an Interest pipeline |
| 43 | * |
| 44 | * Retrieves all segments of Data under a given prefix by maintaining a fixed-size window of |
| 45 | * N Interests in flight. A user-specified callback function is used to notify the arrival of |
| 46 | * each segment of Data. |
| 47 | * |
| 48 | * No guarantees are made as to the order in which segments are fetched or callbacks are invoked, |
| 49 | * i.e. out-of-order delivery is possible. |
| 50 | */ |
Davide Pesavento | 32c0df2 | 2019-10-17 12:00:12 -0400 | [diff] [blame] | 51 | class PipelineInterestsFixed final : public PipelineInterests |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 52 | { |
| 53 | public: |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 54 | PipelineInterestsFixed(Face& face, const Options& opts); |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 55 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 56 | ~PipelineInterestsFixed() final; |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | /** |
| 60 | * @brief fetch all the segments between 0 and m_lastSegmentNo |
| 61 | * |
| 62 | * Starts a fixed-window pipeline with size equal to m_options.maxPipelineSize. The pipeline |
| 63 | * will fetch every segment until the last segment is successfully received or an error occurs. |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 64 | */ |
| 65 | void |
| 66 | doRun() final; |
| 67 | |
| 68 | void |
| 69 | doCancel() final; |
| 70 | |
| 71 | /** |
| 72 | * @brief fetch the next segment that has not been requested yet |
| 73 | * |
| 74 | * @return false if there is an error or all the segments have been fetched, true otherwise |
| 75 | */ |
| 76 | bool |
| 77 | fetchNextSegment(size_t pipeNo); |
| 78 | |
| 79 | void |
| 80 | handleData(const Interest& interest, const Data& data, size_t pipeNo); |
| 81 | |
| 82 | void |
| 83 | handleFail(const std::string& reason, size_t pipeNo); |
| 84 | |
| 85 | private: |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 86 | std::vector<std::pair<std::shared_ptr<DataFetcher>, uint64_t>> m_segmentFetchers; |
Davide Pesavento | b587cfd | 2017-11-04 16:29:50 -0400 | [diff] [blame] | 87 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 88 | /** |
| 89 | * true if one or more segment fetchers encountered an error; if m_hasFinalBlockId |
| 90 | * is false, this is usually not a fatal error for the pipeline |
| 91 | */ |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 92 | bool m_hasFailure = false; |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 95 | } // namespace ndn::chunks |
Chavoosh Ghasemi | 4d36ed5 | 2017-10-31 22:26:25 +0000 | [diff] [blame] | 96 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 97 | #endif // NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_HPP |