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 | |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 169 | private: |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 170 | class PendingSegment; |
| 171 | |
| 172 | SegmentFetcher(Face& face, security::v2::Validator& validator, const Options& options); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 173 | |
| 174 | void |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 175 | fetchFirstSegment(const Interest& baseInterest, |
| 176 | bool isRetransmission, |
| 177 | shared_ptr<SegmentFetcher> self); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 178 | |
| 179 | void |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 180 | fetchSegmentsInWindow(const Interest& origInterest, shared_ptr<SegmentFetcher> self); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 181 | |
| 182 | void |
Muktadir Chowdhury | 1c109b4 | 2018-01-10 08:36:00 +0000 | [diff] [blame] | 183 | afterSegmentReceivedCb(const Interest& origInterest, |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 184 | const Data& data, |
Muktadir Chowdhury | 1c109b4 | 2018-01-10 08:36:00 +0000 | [diff] [blame] | 185 | shared_ptr<SegmentFetcher> self); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 186 | void |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 187 | afterValidationSuccess(const Data& data, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 188 | const Interest& origInterest, |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 189 | std::map<uint64_t, PendingSegment>::iterator pendingSegmentIt, |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 190 | shared_ptr<SegmentFetcher> self); |
| 191 | |
| 192 | void |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 193 | afterValidationFailure(const Data& data, |
| 194 | const security::v2::ValidationError& error, |
| 195 | shared_ptr<SegmentFetcher> self); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 196 | |
| 197 | void |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 198 | afterNackReceivedCb(const Interest& origInterest, |
| 199 | const lp::Nack& nack, |
| 200 | shared_ptr<SegmentFetcher> self); |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 201 | |
| 202 | void |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 203 | afterTimeoutCb(const Interest& origInterest, |
| 204 | shared_ptr<SegmentFetcher> self); |
| 205 | |
| 206 | void |
| 207 | afterNackOrTimeout(const Interest& origInterest, |
| 208 | shared_ptr<SegmentFetcher> self); |
| 209 | |
| 210 | void |
| 211 | finalizeFetch(shared_ptr<SegmentFetcher> self); |
| 212 | |
| 213 | void |
| 214 | windowIncrease(); |
| 215 | |
| 216 | void |
| 217 | windowDecrease(); |
| 218 | |
| 219 | void |
| 220 | signalError(uint32_t code, const std::string& msg); |
| 221 | |
| 222 | void |
| 223 | updateRetransmittedSegment(uint64_t segmentNum, |
| 224 | const PendingInterestId* pendingInterest, |
| 225 | scheduler::EventId timeoutEvent); |
| 226 | |
| 227 | void |
| 228 | cancelExcessInFlightSegments(); |
| 229 | |
| 230 | bool |
| 231 | checkAllSegmentsReceived(); |
| 232 | |
| 233 | time::milliseconds |
| 234 | getEstimatedRto(); |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 235 | |
Muktadir Chowdhury | 1c109b4 | 2018-01-10 08:36:00 +0000 | [diff] [blame] | 236 | public: |
| 237 | /** |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 238 | * @brief Emits upon successful retrieval of the complete data. |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 239 | */ |
| 240 | Signal<SegmentFetcher, ConstBufferPtr> onComplete; |
| 241 | |
| 242 | /** |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 243 | * @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] | 244 | * |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 245 | * Handlers are provided with an error code and a string error message. |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 246 | */ |
| 247 | Signal<SegmentFetcher, uint32_t, std::string> onError; |
| 248 | |
| 249 | /** |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 250 | * @brief Emits whenever a data segment received. |
Muktadir Chowdhury | 1c109b4 | 2018-01-10 08:36:00 +0000 | [diff] [blame] | 251 | */ |
| 252 | Signal<SegmentFetcher, Data> afterSegmentReceived; |
| 253 | |
| 254 | /** |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 255 | * @brief Emits whenever a received data segment has been successfully validated. |
Muktadir Chowdhury | 1c109b4 | 2018-01-10 08:36:00 +0000 | [diff] [blame] | 256 | */ |
| 257 | Signal<SegmentFetcher, Data> afterSegmentValidated; |
| 258 | |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 259 | /** |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 260 | * @brief Emits whenever an Interest for a data segment is nacked. |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 261 | */ |
| 262 | Signal<SegmentFetcher> afterSegmentNacked; |
| 263 | |
| 264 | /** |
Ashlesh Gawande | 279f366 | 2018-08-26 13:42:47 -0500 | [diff] [blame] | 265 | * @brief Emits whenever an Interest for a data segment times out. |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 266 | */ |
| 267 | Signal<SegmentFetcher> afterSegmentTimedOut; |
| 268 | |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 269 | private: |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 270 | enum class SegmentState { |
| 271 | FirstInterest, ///< the first Interest for this segment has been sent |
| 272 | InRetxQueue, ///< the segment is awaiting Interest retransmission |
| 273 | Retransmitted, ///< one or more retransmitted Interests have been sent for this segment |
| 274 | }; |
| 275 | |
| 276 | class PendingSegment |
| 277 | { |
| 278 | public: |
| 279 | SegmentState state; |
| 280 | time::steady_clock::TimePoint sendTime; |
| 281 | const PendingInterestId* id; |
| 282 | scheduler::EventId timeoutEvent; |
| 283 | }; |
| 284 | |
| 285 | NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 286 | static constexpr double MIN_SSTHRESH = 2.0; |
| 287 | |
| 288 | Options m_options; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 289 | Face& m_face; |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 290 | Scheduler m_scheduler; |
Eric Newberry | cc910cd | 2018-05-06 17:01:40 -0700 | [diff] [blame] | 291 | security::v2::Validator& m_validator; |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 292 | RttEstimator m_rttEstimator; |
| 293 | time::milliseconds m_timeout; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 294 | |
Eric Newberry | e345baa | 2018-05-23 18:17:07 -0700 | [diff] [blame] | 295 | time::steady_clock::TimePoint m_timeLastSegmentReceived; |
| 296 | std::queue<uint64_t> m_retxQueue; |
| 297 | Name m_versionedDataName; |
| 298 | uint64_t m_nextSegmentNum; |
| 299 | double m_cwnd; |
| 300 | double m_ssthresh; |
| 301 | int64_t m_nSegmentsInFlight; |
| 302 | int64_t m_nSegments; |
| 303 | uint64_t m_highInterest; |
| 304 | uint64_t m_highData; |
| 305 | uint64_t m_recPoint; |
| 306 | int64_t m_nReceived; |
| 307 | int64_t m_nBytesReceived; |
| 308 | |
| 309 | std::map<uint64_t, Buffer> m_receivedSegments; |
| 310 | std::map<uint64_t, PendingSegment> m_pendingSegments; |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
Muktadir R Chowdhury | f58f8f4 | 2015-09-02 11:56:49 -0500 | [diff] [blame] | 313 | } // namespace util |
| 314 | } // namespace ndn |
Alexander Afanasyev | f3cfab5 | 2014-08-17 22:15:25 -0700 | [diff] [blame] | 315 | |
| 316 | #endif // NDN_UTIL_SEGMENT_FETCHER_HPP |