blob: a317ad210c751c516099a3517187fbf05fc381c5 [file] [log] [blame]
Weiwei Liue4765012016-06-01 00:10:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +00002/*
Davide Pesaventob3570c62022-02-19 19:19:00 -05003 * Copyright (c) 2016-2022, Regents of the University of California,
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +00004 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Weiwei Liue4765012016-06-01 00:10:29 -07006 *
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 Ghasemi4d36ed52017-10-31 22:26:25 +000027 * @author Chavoosh Ghasemi
Weiwei Liue4765012016-06-01 00:10:29 -070028 */
29
schneiderklausd8197df2019-03-16 11:31:40 -070030#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_HPP
31#define NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_HPP
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +000032
Weiwei Liue4765012016-06-01 00:10:29 -070033#include "pipeline-interests.hpp"
34
Davide Pesaventob3570c62022-02-19 19:19:00 -050035namespace ndn::chunks {
Weiwei Liue4765012016-06-01 00:10:29 -070036
37class DataFetcher;
38
Weiwei Liue4765012016-06-01 00:10:29 -070039/**
40 * @brief Service for retrieving Data via an Interest pipeline
41 *
42 * Retrieves all segments of Data under a given prefix by maintaining a fixed-size window of
43 * N Interests in flight. A user-specified callback function is used to notify the arrival of
44 * each segment of Data.
45 *
46 * No guarantees are made as to the order in which segments are fetched or callbacks are invoked,
47 * i.e. out-of-order delivery is possible.
48 */
Davide Pesavento32c0df22019-10-17 12:00:12 -040049class PipelineInterestsFixed final : public PipelineInterests
Weiwei Liue4765012016-06-01 00:10:29 -070050{
51public:
Davide Pesavento97a33b22019-10-17 22:10:47 -040052 PipelineInterestsFixed(Face& face, const Options& opts);
Weiwei Liue4765012016-06-01 00:10:29 -070053
schneiderklausd8197df2019-03-16 11:31:40 -070054 ~PipelineInterestsFixed() final;
Weiwei Liue4765012016-06-01 00:10:29 -070055
56private:
57 /**
58 * @brief fetch all the segments between 0 and m_lastSegmentNo
59 *
60 * Starts a fixed-window pipeline with size equal to m_options.maxPipelineSize. The pipeline
61 * will fetch every segment until the last segment is successfully received or an error occurs.
Weiwei Liue4765012016-06-01 00:10:29 -070062 */
63 void
64 doRun() final;
65
66 void
67 doCancel() final;
68
69 /**
70 * @brief fetch the next segment that has not been requested yet
71 *
72 * @return false if there is an error or all the segments have been fetched, true otherwise
73 */
74 bool
75 fetchNextSegment(size_t pipeNo);
76
77 void
78 handleData(const Interest& interest, const Data& data, size_t pipeNo);
79
80 void
81 handleFail(const std::string& reason, size_t pipeNo);
82
83private:
Weiwei Liue4765012016-06-01 00:10:29 -070084 std::vector<std::pair<shared_ptr<DataFetcher>, uint64_t>> m_segmentFetchers;
Davide Pesaventob587cfd2017-11-04 16:29:50 -040085
Weiwei Liue4765012016-06-01 00:10:29 -070086 /**
87 * true if one or more segment fetchers encountered an error; if m_hasFinalBlockId
88 * is false, this is usually not a fatal error for the pipeline
89 */
Davide Pesavento97a33b22019-10-17 22:10:47 -040090 bool m_hasFailure = false;
Weiwei Liue4765012016-06-01 00:10:29 -070091};
92
Davide Pesaventob3570c62022-02-19 19:19:00 -050093} // namespace ndn::chunks
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +000094
schneiderklausd8197df2019-03-16 11:31:40 -070095#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_HPP