Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0c13951 | 2018-11-03 18:23:38 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California. |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "write-handle.hpp" |
| 21 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 22 | #include <ndn-cxx/util/logger.hpp> |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 23 | #include <ndn-cxx/util/random.hpp> |
| 24 | |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 25 | namespace repo { |
| 26 | |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 27 | NDN_LOG_INIT(repo.WriteHandle); |
| 28 | |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 29 | static const int DEFAULT_CREDIT = 12; |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 30 | static const bool DEFAULT_CANBE_PREFIX = false; |
| 31 | static const milliseconds MAX_TIMEOUT(60_s); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 32 | static const milliseconds NOEND_TIMEOUT(10000_ms); |
| 33 | static const milliseconds PROCESS_DELETE_TIME(10000_ms); |
| 34 | static const milliseconds DEFAULT_INTEREST_LIFETIME(4000_ms); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 35 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 36 | WriteHandle::WriteHandle(Face& face, RepoStorage& storageHandle, ndn::mgmt::Dispatcher& dispatcher, |
| 37 | Scheduler& scheduler, Validator& validator) |
| 38 | : CommandBaseHandle(face, storageHandle, scheduler, validator) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 39 | , m_validator(validator) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 40 | , m_credit(DEFAULT_CREDIT) |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 41 | , m_canBePrefix(DEFAULT_CANBE_PREFIX) |
| 42 | , m_maxTimeout(MAX_TIMEOUT) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 43 | , m_noEndTimeout(NOEND_TIMEOUT) |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 44 | , m_interestLifetime(DEFAULT_INTEREST_LIFETIME) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 45 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 46 | dispatcher.addControlCommand<RepoCommandParameter>(ndn::PartialName("insert"), |
| 47 | makeAuthorization(), |
| 48 | std::bind(&WriteHandle::validateParameters<InsertCommand>, this, _1), |
| 49 | std::bind(&WriteHandle::handleInsertCommand, this, _1, _2, _3, _4)); |
| 50 | |
| 51 | dispatcher.addControlCommand<RepoCommandParameter>(ndn::PartialName("insert check"), |
| 52 | makeAuthorization(), |
| 53 | std::bind(&WriteHandle::validateParameters<InsertCheckCommand>, this, _1), |
| 54 | std::bind(&WriteHandle::handleCheckCommand, this, _1, _2, _3, _4)); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void |
| 58 | WriteHandle::deleteProcess(ProcessId processId) |
| 59 | { |
| 60 | m_processes.erase(processId); |
| 61 | } |
| 62 | |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 63 | void |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 64 | WriteHandle::handleInsertCommand(const Name& prefix, const Interest& interest, |
| 65 | const ndn::mgmt::ControlParameters& parameter, |
| 66 | const ndn::mgmt::CommandContinuation& done) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 67 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 68 | RepoCommandParameter* repoParameter = |
| 69 | dynamic_cast<RepoCommandParameter*>(const_cast<ndn::mgmt::ControlParameters*>(¶meter)); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 70 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 71 | if (repoParameter->hasStartBlockId() || repoParameter->hasEndBlockId()) { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 72 | processSegmentedInsertCommand(interest, *repoParameter, done); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 73 | } |
| 74 | else { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 75 | processSingleInsertCommand(interest, *repoParameter, done); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 76 | } |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 77 | if (repoParameter->hasInterestLifetime()) |
| 78 | m_interestLifetime = repoParameter->getInterestLifetime(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 82 | WriteHandle::onData(const Interest& interest, const Data& data, ProcessId processId) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 83 | { |
Shuo Chen | c88c87d | 2014-06-25 20:21:02 +0800 | [diff] [blame] | 84 | m_validator.validate(data, |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 85 | std::bind(&WriteHandle::onDataValidated, this, interest, _1, processId), |
| 86 | [](const Data& data, const ValidationError& error){NDN_LOG_ERROR("Error: " << error);}); |
Shuo Chen | c88c87d | 2014-06-25 20:21:02 +0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 90 | WriteHandle::onDataValidated(const Interest& interest, const Data& data, ProcessId processId) |
Shuo Chen | c88c87d | 2014-06-25 20:21:02 +0800 | [diff] [blame] | 91 | { |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 92 | if (m_processes.count(processId) == 0) { |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | ProcessInfo& process = m_processes[processId]; |
| 97 | RepoCommandResponse& response = process.response; |
| 98 | |
| 99 | if (response.getInsertNum() == 0) { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 100 | storageHandle.insertData(data); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 101 | response.setInsertNum(1); |
| 102 | } |
| 103 | |
| 104 | deferredDeleteProcess(processId); |
| 105 | } |
| 106 | |
| 107 | void |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 108 | WriteHandle::onTimeout(const Interest& interest, ProcessId processId) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 109 | { |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 110 | NDN_LOG_DEBUG("Timeout" << std::endl); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 111 | m_processes.erase(processId); |
| 112 | } |
| 113 | |
| 114 | void |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 115 | WriteHandle::processSingleInsertCommand(const Interest& interest, RepoCommandParameter& parameter, |
| 116 | const ndn::mgmt::CommandContinuation& done) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 117 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 118 | ProcessId processId = ndn::random::generateWord64(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 119 | |
| 120 | ProcessInfo& process = m_processes[processId]; |
| 121 | |
| 122 | RepoCommandResponse& response = process.response; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 123 | response.setCode(100); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 124 | response.setProcessId(processId); |
| 125 | response.setInsertNum(0); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 126 | response.setBody(response.wireEncode()); |
| 127 | done(response); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 128 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 129 | response.setCode(300); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 130 | Interest fetchInterest(parameter.getName()); |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 131 | fetchInterest.setCanBePrefix(m_canBePrefix); |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 132 | fetchInterest.setInterestLifetime(m_interestLifetime); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 133 | face.expressInterest(fetchInterest, |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 134 | std::bind(&WriteHandle::onData, this, _1, _2, processId), |
| 135 | std::bind(&WriteHandle::onTimeout, this, _1, processId), // Nack |
| 136 | std::bind(&WriteHandle::onTimeout, this, _1, processId)); |
| 137 | } |
| 138 | |
| 139 | void |
| 140 | WriteHandle::segInit(ProcessId processId, const RepoCommandParameter& parameter) |
| 141 | { |
| 142 | // use SegmentFetcher to send fetch interest. |
| 143 | ProcessInfo& process = m_processes[processId]; |
| 144 | Name name = parameter.getName(); |
| 145 | SegmentNo startBlockId = parameter.getStartBlockId(); |
| 146 | |
| 147 | uint64_t initialCredit = m_credit; |
| 148 | |
| 149 | if (parameter.hasEndBlockId()) { |
| 150 | initialCredit = |
| 151 | std::min(initialCredit, parameter.getEndBlockId() - parameter.getStartBlockId() + 1); |
| 152 | } |
| 153 | else { |
| 154 | // set noEndTimeout timer |
| 155 | process.noEndTime = ndn::time::steady_clock::now() + |
| 156 | m_noEndTimeout; |
| 157 | } |
| 158 | |
| 159 | Name fetchName = name; |
| 160 | SegmentNo segment = startBlockId; |
| 161 | fetchName.appendSegment(segment); |
| 162 | Interest interest(fetchName); |
| 163 | |
| 164 | ndn::util::SegmentFetcher::Options options; |
| 165 | options.initCwnd = initialCredit; |
| 166 | options.interestLifetime = m_interestLifetime; |
| 167 | options.maxTimeout = m_maxTimeout; |
| 168 | auto fetcher = ndn::util::SegmentFetcher::start(face, interest, m_validator, options); |
| 169 | fetcher->onError.connect([] (uint32_t errorCode, const std::string& errorMsg) |
| 170 | {NDN_LOG_ERROR("Error: " << errorMsg);}); |
| 171 | fetcher->afterSegmentValidated.connect([this, &fetcher, &processId] (const Data& data) |
| 172 | {onSegmentData(*fetcher, data, processId);}); |
| 173 | fetcher->afterSegmentTimedOut.connect([this, &fetcher, &processId] () |
| 174 | {onSegmentTimeout(*fetcher, processId);}); |
| 175 | } |
| 176 | |
| 177 | void |
| 178 | WriteHandle::onSegmentData(ndn::util::SegmentFetcher& fetcher, const Data& data, ProcessId processId) |
| 179 | { |
| 180 | auto it = m_processes.find(processId); |
| 181 | if (it == m_processes.end()) { |
| 182 | fetcher.stop(); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | RepoCommandResponse& response = it->second.response; |
| 187 | |
| 188 | //insert data |
| 189 | if (storageHandle.insertData(data)) { |
| 190 | response.setInsertNum(response.getInsertNum() + 1); |
| 191 | } |
| 192 | |
| 193 | ProcessInfo& process = m_processes[processId]; |
| 194 | //read whether notime timeout |
| 195 | if (!response.hasEndBlockId()) { |
| 196 | |
| 197 | ndn::time::steady_clock::TimePoint& noEndTime = process.noEndTime; |
| 198 | ndn::time::steady_clock::TimePoint now = ndn::time::steady_clock::now(); |
| 199 | |
| 200 | if (now > noEndTime) { |
| 201 | NDN_LOG_DEBUG("noEndtimeout: " << processId); |
| 202 | //StatusCode should be refreshed as 405 |
| 203 | response.setCode(405); |
| 204 | //schedule a delete event |
| 205 | deferredDeleteProcess(processId); |
| 206 | fetcher.stop(); |
| 207 | return; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | //read whether this process has total ends, if ends, remove control info from the maps |
| 212 | if (response.hasEndBlockId()) { |
| 213 | uint64_t nSegments = response.getEndBlockId() - response.getStartBlockId() + 1; |
| 214 | if (response.getInsertNum() >= nSegments) { |
| 215 | //All the data has been inserted, StatusCode is refreshed as 200 |
| 216 | response.setCode(200); |
| 217 | deferredDeleteProcess(processId); |
| 218 | fetcher.stop(); |
| 219 | return; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void |
| 225 | WriteHandle::onSegmentTimeout(ndn::util::SegmentFetcher& fetcher, ProcessId processId) |
| 226 | { |
| 227 | NDN_LOG_DEBUG("SegTimeout"); |
| 228 | if (m_processes.count(processId) == 0) { |
| 229 | fetcher.stop(); |
| 230 | return; |
| 231 | } |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 235 | WriteHandle::processSegmentedInsertCommand(const Interest& interest, RepoCommandParameter& parameter, |
| 236 | const ndn::mgmt::CommandContinuation& done) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 237 | { |
| 238 | if (parameter.hasEndBlockId()) { |
| 239 | //normal fetch segment |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 240 | SegmentNo startBlockId = parameter.hasStartBlockId() ? parameter.getStartBlockId() : 0; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 241 | SegmentNo endBlockId = parameter.getEndBlockId(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 242 | if (startBlockId > endBlockId) { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 243 | done(negativeReply("Malformed Command", 403)); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 244 | return; |
| 245 | } |
| 246 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 247 | ProcessId processId = ndn::random::generateWord64(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 248 | ProcessInfo& process = m_processes[processId]; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 249 | RepoCommandResponse& response = process.response; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 250 | response.setCode(100); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 251 | response.setProcessId(processId); |
| 252 | response.setInsertNum(0); |
| 253 | response.setStartBlockId(startBlockId); |
| 254 | response.setEndBlockId(endBlockId); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 255 | response.setBody(response.wireEncode()); |
| 256 | done(response); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 257 | |
| 258 | //300 means data fetching is in progress |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 259 | response.setCode(300); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 260 | |
| 261 | segInit(processId, parameter); |
| 262 | } |
| 263 | else { |
| 264 | //no EndBlockId, so fetch FinalBlockId in data, if timeout, stop |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 265 | ProcessId processId = ndn::random::generateWord64(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 266 | ProcessInfo& process = m_processes[processId]; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 267 | RepoCommandResponse& response = process.response; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 268 | response.setCode(100); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 269 | response.setProcessId(processId); |
| 270 | response.setInsertNum(0); |
| 271 | response.setStartBlockId(parameter.getStartBlockId()); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 272 | response.setBody(response.wireEncode()); |
| 273 | done(response); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 274 | |
| 275 | //300 means data fetching is in progress |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 276 | response.setCode(300); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 277 | |
| 278 | segInit(processId, parameter); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | void |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 283 | WriteHandle::handleCheckCommand(const Name& prefix, const Interest& interest, |
| 284 | const ndn::mgmt::ControlParameters& parameter, |
| 285 | const ndn::mgmt::CommandContinuation& done) |
| 286 | { |
| 287 | const RepoCommandParameter& repoParameter = dynamic_cast<const RepoCommandParameter&>(parameter); |
| 288 | |
| 289 | //check whether this process exists |
| 290 | ProcessId processId = repoParameter.getProcessId(); |
| 291 | if (m_processes.count(processId) == 0) { |
| 292 | NDN_LOG_DEBUG("no such processId: " << processId); |
| 293 | done(negativeReply("No such this process is in progress", 404)); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | ProcessInfo& process = m_processes[processId]; |
| 298 | |
| 299 | RepoCommandResponse& response = process.response; |
| 300 | |
| 301 | //Check whether it is single data fetching |
| 302 | if (!response.hasStartBlockId() && !response.hasEndBlockId()) { |
| 303 | done(response); |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | //read if noEndtimeout |
| 308 | if (!response.hasEndBlockId()) { |
| 309 | extendNoEndTime(process); |
| 310 | done(response); |
| 311 | return; |
| 312 | } |
| 313 | else { |
| 314 | done(response); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | void |
| 319 | WriteHandle::deferredDeleteProcess(ProcessId processId) |
| 320 | { |
| 321 | scheduler.scheduleEvent(PROCESS_DELETE_TIME, |
| 322 | std::bind(&WriteHandle::deleteProcess, this, processId)); |
| 323 | } |
| 324 | |
| 325 | void |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 326 | WriteHandle::extendNoEndTime(ProcessInfo& process) |
| 327 | { |
| 328 | ndn::time::steady_clock::TimePoint& noEndTime = process.noEndTime; |
| 329 | ndn::time::steady_clock::TimePoint now = ndn::time::steady_clock::now(); |
| 330 | RepoCommandResponse& response = process.response; |
| 331 | if (now > noEndTime) { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 332 | response.setCode(405); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 333 | return; |
| 334 | } |
| 335 | //extends noEndTime |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 336 | process.noEndTime = ndn::time::steady_clock::now() + m_noEndTimeout; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 337 | |
| 338 | } |
| 339 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 340 | RepoCommandResponse |
| 341 | WriteHandle::negativeReply(std::string text, int statusCode) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 342 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 343 | RepoCommandResponse response(statusCode, text); |
| 344 | response.setBody(response.wireEncode()); |
| 345 | |
| 346 | return response; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 349 | } // namespace repo |