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