Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0990441 | 2021-03-24 16:40:53 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2021 Regents of the University of California. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Davide Pesavento | 0990441 | 2021-03-24 16:40:53 -0400 | [diff] [blame] | 22 | #ifndef NDN_CXX_UTIL_SEGMENT_FETCHER_HPP |
| 23 | #define NDN_CXX_UTIL_SEGMENT_FETCHER_HPP |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 25 | #include "ndn-cxx/face.hpp" |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 26 | #include "ndn-cxx/security/validator.hpp" |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 27 | #include "ndn-cxx/util/rtt-estimator.hpp" |
| 28 | #include "ndn-cxx/util/scheduler.hpp" |
| 29 | #include "ndn-cxx/util/signal.hpp" |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 30 | |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 31 | #include <queue> |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 32 | #include <set> |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 34 | namespace ndn { |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 35 | namespace util { |
| 36 | |
| 37 | /** |
Eric Newberry | 2b765f8 | 2018-06-25 14:51:13 -0700 | [diff] [blame] | 38 | * @brief Utility class to fetch the latest version of a segmented object. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 39 | * |
Eric Newberry | 2b765f8 | 2018-06-25 14:51:13 -0700 | [diff] [blame] | 40 | * SegmentFetcher assumes that segments in the object are named `/<prefix>/<version>/<segment>`, |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 41 | * where: |
Alexander Afanasyev | f2a4622 | 2015-09-17 18:01:30 -0700 | [diff] [blame] | 42 | * - `<prefix>` is the specified prefix, |
| 43 | * - `<version>` is an unknown version that needs to be discovered, and |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 44 | * - `<segment>` is a segment number (the number of segments in the object is unknown until a Data |
| 45 | * packet containing the `FinalBlockId` field is received). |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 46 | * |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 47 | * SegmentFetcher implements the following logic: |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 48 | * |
Eric Newberry | 2b765f8 | 2018-06-25 14:51:13 -0700 | [diff] [blame] | 49 | * 1. Express an Interest to discover the latest version of the object: |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 50 | * |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 51 | * Interest: `/<prefix>?CanBePrefix&MustBeFresh` |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 52 | * |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 53 | * 2. Infer the latest version of the object: `<version> = Data.getName().get(-2)`. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 54 | * |
Eric Newberry | 2b765f8 | 2018-06-25 14:51:13 -0700 | [diff] [blame] | 55 | * 3. Keep sending Interests for future segments until an error occurs or the number of segments |
| 56 | * indicated by the FinalBlockId in a received Data packet is reached. This retrieval will start |
| 57 | * at segment 1 if segment 0 was received in response to the Interest expressed in step 2; |
| 58 | * otherwise, retrieval will start at segment 0. By default, congestion control will be used to |
| 59 | * manage the Interest window size. Interests expressed in this step will follow this Name |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 60 | * format: `/<prefix>/<version>/<segment=(N)>`. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 61 | * |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 62 | * 4. If set to 'block' mode, signal #onComplete passing a memory buffer that combines the content |
| 63 | * of all segments in the object. If set to 'in order' mode, signal #onInOrderData is triggered |
| 64 | * upon validation of each segment in segment order, storing later segments that arrived out of |
| 65 | * order internally until all earlier segments have arrived and have been validated. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 66 | * |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 67 | * If an error occurs during the fetching process, #onError is signaled with one of the error codes |
| 68 | * from SegmentFetcher::ErrorCode. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 69 | * |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 70 | * A Validator instance must be specified to validate individual segments. Every time a segment has |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 71 | * been successfully validated, #afterSegmentValidated will be signaled. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 72 | * |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 73 | * Example: |
Eric Newberry | 2b765f8 | 2018-06-25 14:51:13 -0700 | [diff] [blame] | 74 | * @code |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 75 | * void |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 76 | * afterFetchComplete(ConstBufferPtr data) |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 77 | * { |
| 78 | * ... |
| 79 | * } |
| 80 | * |
| 81 | * void |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 82 | * afterFetchError(uint32_t errorCode, const std::string& errorMsg) |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 83 | * { |
| 84 | * ... |
| 85 | * } |
| 86 | * |
| 87 | * ... |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 88 | * auto fetcher = SegmentFetcher::start(face, Interest("/data/prefix"), validator); |
| 89 | * fetcher->onComplete.connect(bind(&afterFetchComplete, this, _1)); |
| 90 | * fetcher->onError.connect(bind(&afterFetchError, this, _1, _2)); |
Eric Newberry | 2b765f8 | 2018-06-25 14:51:13 -0700 | [diff] [blame] | 91 | * @endcode |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 92 | */ |
| 93 | class SegmentFetcher : noncopyable |
| 94 | { |
| 95 | public: |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 96 | /** |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 97 | * @brief Error codes passed to #onError. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 98 | */ |
| 99 | enum ErrorCode { |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 100 | /// Retrieval timed out because the maximum timeout between the successful receipt of segments was exceeded |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 101 | INTEREST_TIMEOUT = 1, |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 102 | /// One of the retrieved Data packets lacked a segment number in the last Name component (excl. implicit digest) |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 103 | DATA_HAS_NO_SEGMENT = 2, |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 104 | /// One of the retrieved segments failed user-provided validation |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 105 | SEGMENT_VALIDATION_FAIL = 3, |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 106 | /// An unrecoverable Nack was received during retrieval |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 107 | NACK_ERROR = 4, |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 108 | /// A received FinalBlockId did not contain a segment component |
| 109 | FINALBLOCKID_NOT_SEGMENT = 5, |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | class Options |
| 113 | { |
| 114 | public: |
| 115 | Options() |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | validate(); |
| 121 | |
| 122 | public: |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 123 | time::milliseconds interestLifetime = 4_s; ///< lifetime of sent Interests - independent of Interest timeout |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 124 | time::milliseconds maxTimeout = 60_s; ///< maximum allowed time between successful receipt of segments |
| 125 | bool inOrder = false; ///< true for 'in order' mode, false for 'block' mode |
| 126 | bool useConstantInterestTimeout = false; ///< if true, Interest timeout is kept at `maxTimeout` |
| 127 | bool useConstantCwnd = false; ///< if true, window size is kept at `initCwnd` |
| 128 | bool disableCwa = false; ///< disable Conservative Window Adaptation |
| 129 | bool resetCwndToInit = false; ///< reduce cwnd to initCwnd when loss event occurs |
| 130 | bool ignoreCongMarks = false; ///< disable window decrease after congestion mark received |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 131 | double initCwnd = 1.0; ///< initial congestion window size |
| 132 | double initSsthresh = std::numeric_limits<double>::max(); ///< initial slow start threshold |
| 133 | double aiStep = 1.0; ///< additive increase step (in segments) |
| 134 | double mdCoef = 0.5; ///< multiplicative decrease coefficient |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 135 | RttEstimator::Options rttOptions; ///< options for RTT estimator |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 136 | size_t flowControlWindow = 25000; ///< maximum number of segments stored in the reorder buffer |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /** |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 140 | * @brief Initiates segment fetching. |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 141 | * |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 142 | * Transfer completion, failure, and progress are indicated via signals. |
| 143 | * |
| 144 | * @param face Reference to the Face that should be used to fetch data. |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 145 | * @param baseInterest Interest for the initial segment of requested data. |
Eric Newberry | 2b765f8 | 2018-06-25 14:51:13 -0700 | [diff] [blame] | 146 | * This interest may include a custom InterestLifetime and parameters that |
| 147 | * will propagate to all subsequent Interests. The only exception is that the |
| 148 | * initial Interest will be forced to include the "CanBePrefix=true" and |
| 149 | * "MustBeFresh=true" parameters, which will not be included in subsequent |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 150 | * Interests. |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 151 | * @param validator Reference to the Validator the fetcher will use to validate data. |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 152 | * The caller must ensure the validator remains valid until either #onComplete |
| 153 | * or #onError has been signaled. |
| 154 | * @param options Options controlling the transfer. |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 155 | * |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 156 | * @return A shared_ptr to the constructed SegmentFetcher. |
| 157 | * This shared_ptr is kept internally for the lifetime of the transfer. |
| 158 | * Therefore, it does not need to be saved and is provided here so that the |
| 159 | * SegmentFetcher's signals can be connected to. |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 160 | */ |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 161 | static shared_ptr<SegmentFetcher> |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 162 | start(Face& face, |
| 163 | const Interest& baseInterest, |
Davide Pesavento | f2cae61 | 2021-03-24 18:47:05 -0400 | [diff] [blame] | 164 | security::Validator& validator, |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 165 | const Options& options = Options()); |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 166 | |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 167 | /** |
| 168 | * @brief Stops fetching. |
| 169 | * |
| 170 | * This cancels all interests that are still pending. |
| 171 | */ |
| 172 | void |
| 173 | stop(); |
| 174 | |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 175 | private: |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 176 | class PendingSegment; |
| 177 | |
Davide Pesavento | f2cae61 | 2021-03-24 18:47:05 -0400 | [diff] [blame] | 178 | SegmentFetcher(Face& face, security::Validator& validator, const Options& options); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 179 | |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 180 | static bool |
| 181 | shouldStop(const weak_ptr<SegmentFetcher>& weakSelf); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 182 | |
| 183 | void |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 184 | fetchFirstSegment(const Interest& baseInterest, bool isRetransmission); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 185 | |
| 186 | void |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 187 | fetchSegmentsInWindow(const Interest& origInterest); |
| 188 | |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 189 | void |
Junxiao Shi | a5f233e | 2019-03-18 09:39:22 -0600 | [diff] [blame] | 190 | sendInterest(uint64_t segNum, const Interest& interest, bool isRetransmission); |
| 191 | |
| 192 | void |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 193 | afterSegmentReceivedCb(const Interest& origInterest, const Data& data, |
| 194 | const weak_ptr<SegmentFetcher>& weakSelf); |
| 195 | |
| 196 | void |
| 197 | afterValidationSuccess(const Data& data, const Interest& origInterest, |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 198 | std::map<uint64_t, PendingSegment>::iterator pendingSegmentIt, |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 199 | const weak_ptr<SegmentFetcher>& weakSelf); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 200 | |
| 201 | void |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 202 | afterValidationFailure(const Data& data, |
Davide Pesavento | f2cae61 | 2021-03-24 18:47:05 -0400 | [diff] [blame] | 203 | const security::ValidationError& error, |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 204 | const weak_ptr<SegmentFetcher>& weakSelf); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 205 | |
| 206 | void |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 207 | afterNackReceivedCb(const Interest& origInterest, const lp::Nack& nack, |
| 208 | const weak_ptr<SegmentFetcher>& weakSelf); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 209 | |
| 210 | void |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 211 | afterTimeoutCb(const Interest& origInterest, |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 212 | const weak_ptr<SegmentFetcher>& weakSelf); |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 213 | |
| 214 | void |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 215 | afterNackOrTimeout(const Interest& origInterest); |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 216 | |
| 217 | void |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 218 | finalizeFetch(); |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 219 | |
| 220 | void |
| 221 | windowIncrease(); |
| 222 | |
| 223 | void |
| 224 | windowDecrease(); |
| 225 | |
| 226 | void |
| 227 | signalError(uint32_t code, const std::string& msg); |
| 228 | |
| 229 | void |
| 230 | updateRetransmittedSegment(uint64_t segmentNum, |
Junxiao Shi | 4fdcb27 | 2019-02-11 15:05:46 -0700 | [diff] [blame] | 231 | const PendingInterestHandle& pendingInterest, |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 232 | scheduler::EventId timeoutEvent); |
| 233 | |
| 234 | void |
| 235 | cancelExcessInFlightSegments(); |
| 236 | |
| 237 | bool |
| 238 | checkAllSegmentsReceived(); |
| 239 | |
| 240 | time::milliseconds |
| 241 | getEstimatedRto(); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 242 | |
Muktadir Chowdhury | 1c109b4 | 2018-01-10 08:36:00 +0000 | [diff] [blame] | 243 | public: |
| 244 | /** |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 245 | * @brief Emitted upon successful retrieval of the complete object (all segments). |
| 246 | * @note Emitted only if SegmentFetcher is operating in 'block' mode. |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 247 | */ |
| 248 | Signal<SegmentFetcher, ConstBufferPtr> onComplete; |
| 249 | |
| 250 | /** |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 251 | * @brief Emitted when the retrieval could not be completed due to an error. |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 252 | * |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 253 | * Handlers are provided with an error code and a string error message. |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 254 | */ |
| 255 | Signal<SegmentFetcher, uint32_t, std::string> onError; |
| 256 | |
| 257 | /** |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 258 | * @brief Emitted whenever a data segment received. |
Muktadir Chowdhury | 1c109b4 | 2018-01-10 08:36:00 +0000 | [diff] [blame] | 259 | */ |
| 260 | Signal<SegmentFetcher, Data> afterSegmentReceived; |
| 261 | |
| 262 | /** |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 263 | * @brief Emitted whenever a received data segment has been successfully validated. |
Muktadir Chowdhury | 1c109b4 | 2018-01-10 08:36:00 +0000 | [diff] [blame] | 264 | */ |
| 265 | Signal<SegmentFetcher, Data> afterSegmentValidated; |
| 266 | |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 267 | /** |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 268 | * @brief Emitted whenever an Interest for a data segment is nacked. |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 269 | */ |
| 270 | Signal<SegmentFetcher> afterSegmentNacked; |
| 271 | |
| 272 | /** |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 273 | * @brief Emitted whenever an Interest for a data segment times out. |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 274 | */ |
| 275 | Signal<SegmentFetcher> afterSegmentTimedOut; |
| 276 | |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 277 | /** |
| 278 | * @brief Emitted after each data segment in segment order has been validated. |
| 279 | * @note Emitted only if SegmentFetcher is operating in 'in order' mode. |
| 280 | */ |
| 281 | Signal<SegmentFetcher, ConstBufferPtr> onInOrderData; |
| 282 | |
| 283 | /** |
| 284 | * @brief Emitted on successful retrieval of all segments in 'in order' mode. |
| 285 | * @note Emitted only if SegmentFetcher is operating in 'in order' mode. |
| 286 | */ |
| 287 | Signal<SegmentFetcher> onInOrderComplete; |
| 288 | |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 289 | private: |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 290 | enum class SegmentState { |
| 291 | FirstInterest, ///< the first Interest for this segment has been sent |
| 292 | InRetxQueue, ///< the segment is awaiting Interest retransmission |
| 293 | Retransmitted, ///< one or more retransmitted Interests have been sent for this segment |
| 294 | }; |
| 295 | |
| 296 | class PendingSegment |
| 297 | { |
| 298 | public: |
| 299 | SegmentState state; |
| 300 | time::steady_clock::TimePoint sendTime; |
Junxiao Shi | 4fdcb27 | 2019-02-11 15:05:46 -0700 | [diff] [blame] | 301 | ScopedPendingInterestHandle hdl; |
| 302 | scheduler::ScopedEventId timeoutEvent; |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 306 | static constexpr double MIN_SSTHRESH = 2.0; |
| 307 | |
Ashlesh Gawande | 679dbb0 | 2018-08-21 11:43:21 -0500 | [diff] [blame] | 308 | shared_ptr<SegmentFetcher> m_this; |
| 309 | |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 310 | Options m_options; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 311 | Face& m_face; |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 312 | Scheduler m_scheduler; |
Davide Pesavento | f2cae61 | 2021-03-24 18:47:05 -0400 | [diff] [blame] | 313 | security::Validator& m_validator; |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 314 | RttEstimator m_rttEstimator; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 315 | |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 316 | time::steady_clock::TimePoint m_timeLastSegmentReceived; |
| 317 | std::queue<uint64_t> m_retxQueue; |
| 318 | Name m_versionedDataName; |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 319 | uint64_t m_nextSegmentNum = 0; |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 320 | double m_cwnd; |
| 321 | double m_ssthresh; |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 322 | int64_t m_nSegmentsInFlight = 0; |
| 323 | int64_t m_nSegments = 0; |
| 324 | uint64_t m_highInterest = 0; |
| 325 | uint64_t m_highData = 0; |
| 326 | uint64_t m_recPoint = 0; |
| 327 | int64_t m_nReceived = 0; |
| 328 | int64_t m_nBytesReceived = 0; |
| 329 | uint64_t m_nextSegmentInOrder = 0; |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 330 | |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 331 | std::map<uint64_t, Buffer> m_segmentBuffer; |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 332 | std::map<uint64_t, PendingSegment> m_pendingSegments; |
jrclark2 | 40ebaad | 2020-04-02 11:18:00 -0500 | [diff] [blame] | 333 | std::set<uint64_t> m_receivedSegments; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 334 | }; |
| 335 | |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 336 | } // namespace util |
| 337 | } // namespace ndn |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 338 | |
Davide Pesavento | 0990441 | 2021-03-24 16:40:53 -0400 | [diff] [blame] | 339 | #endif // NDN_CXX_UTIL_SEGMENT_FETCHER_HPP |