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 | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, 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 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 29 | const int DEFAULT_CREDIT = 12; |
| 30 | const time::milliseconds NOEND_TIMEOUT = 10_s; |
| 31 | const time::milliseconds PROCESS_DELETE_TIME = 10_s; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 32 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 33 | WriteHandle::WriteHandle(Face& face, RepoStorage& storageHandle, ndn::mgmt::Dispatcher& dispatcher, |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 34 | Scheduler& scheduler, ndn::security::Validator& validator) |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 35 | : CommandBaseHandle(face, storageHandle, scheduler, validator) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 36 | , m_validator(validator) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 37 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 38 | dispatcher.addControlCommand<RepoCommandParameter>(ndn::PartialName("insert"), |
| 39 | makeAuthorization(), |
| 40 | std::bind(&WriteHandle::validateParameters<InsertCommand>, this, _1), |
| 41 | std::bind(&WriteHandle::handleInsertCommand, this, _1, _2, _3, _4)); |
| 42 | |
| 43 | dispatcher.addControlCommand<RepoCommandParameter>(ndn::PartialName("insert check"), |
| 44 | makeAuthorization(), |
| 45 | std::bind(&WriteHandle::validateParameters<InsertCheckCommand>, this, _1), |
| 46 | std::bind(&WriteHandle::handleCheckCommand, this, _1, _2, _3, _4)); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void |
| 50 | WriteHandle::deleteProcess(ProcessId processId) |
| 51 | { |
| 52 | m_processes.erase(processId); |
| 53 | } |
| 54 | |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 55 | void |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 56 | WriteHandle::handleInsertCommand(const Name& prefix, const Interest& interest, |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 57 | const ndn::mgmt::ControlParameters& params, |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 58 | const ndn::mgmt::CommandContinuation& done) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 59 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 60 | auto& repoParam = dynamic_cast<RepoCommandParameter&>(const_cast<ndn::mgmt::ControlParameters&>(params)); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 61 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 62 | if (repoParam.hasStartBlockId() || repoParam.hasEndBlockId()) { |
| 63 | processSegmentedInsertCommand(interest, repoParam, done); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 64 | } |
| 65 | else { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 66 | processSingleInsertCommand(interest, repoParam, done); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 67 | } |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 68 | if (repoParam.hasInterestLifetime()) { |
| 69 | m_interestLifetime = repoParam.getInterestLifetime(); |
| 70 | } |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 74 | WriteHandle::onData(const Interest& interest, const Data& data, ProcessId processId) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 75 | { |
Shuo Chen | c88c87d | 2014-06-25 20:21:02 +0800 | [diff] [blame] | 76 | m_validator.validate(data, |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 77 | std::bind(&WriteHandle::onDataValidated, this, interest, _1, processId), |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 78 | [] (auto&&, const auto& error) { NDN_LOG_ERROR("Error: " << error); }); |
Shuo Chen | c88c87d | 2014-06-25 20:21:02 +0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 82 | WriteHandle::onDataValidated(const Interest& interest, const Data& data, ProcessId processId) |
Shuo Chen | c88c87d | 2014-06-25 20:21:02 +0800 | [diff] [blame] | 83 | { |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 84 | if (m_processes.count(processId) == 0) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | ProcessInfo& process = m_processes[processId]; |
| 89 | RepoCommandResponse& response = process.response; |
| 90 | |
| 91 | if (response.getInsertNum() == 0) { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 92 | storageHandle.insertData(data); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 93 | response.setInsertNum(1); |
| 94 | } |
| 95 | |
| 96 | deferredDeleteProcess(processId); |
| 97 | } |
| 98 | |
| 99 | void |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 100 | WriteHandle::onTimeout(const Interest& interest, ProcessId processId) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 101 | { |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 102 | NDN_LOG_DEBUG("Timeout" << std::endl); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 103 | m_processes.erase(processId); |
| 104 | } |
| 105 | |
| 106 | void |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 107 | WriteHandle::processSingleInsertCommand(const Interest& interest, RepoCommandParameter& parameter, |
| 108 | const ndn::mgmt::CommandContinuation& done) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 109 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 110 | ProcessId processId = ndn::random::generateWord64(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 111 | |
| 112 | ProcessInfo& process = m_processes[processId]; |
| 113 | |
| 114 | RepoCommandResponse& response = process.response; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 115 | response.setCode(100); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 116 | response.setProcessId(processId); |
| 117 | response.setInsertNum(0); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 118 | response.setBody(response.wireEncode()); |
| 119 | done(response); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 120 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 121 | response.setCode(300); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 122 | Interest fetchInterest(parameter.getName()); |
Weiqi Shi | 098f91c | 2014-07-23 17:41:35 -0700 | [diff] [blame] | 123 | fetchInterest.setInterestLifetime(m_interestLifetime); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 124 | face.expressInterest(fetchInterest, |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 125 | std::bind(&WriteHandle::onData, this, _1, _2, processId), |
| 126 | std::bind(&WriteHandle::onTimeout, this, _1, processId), // Nack |
| 127 | std::bind(&WriteHandle::onTimeout, this, _1, processId)); |
| 128 | } |
| 129 | |
| 130 | void |
| 131 | WriteHandle::segInit(ProcessId processId, const RepoCommandParameter& parameter) |
| 132 | { |
| 133 | // use SegmentFetcher to send fetch interest. |
| 134 | ProcessInfo& process = m_processes[processId]; |
| 135 | Name name = parameter.getName(); |
| 136 | SegmentNo startBlockId = parameter.getStartBlockId(); |
| 137 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 138 | int initialCredit = DEFAULT_CREDIT; |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 139 | if (parameter.hasEndBlockId()) { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 140 | initialCredit = std::min<int>(initialCredit, parameter.getEndBlockId() - parameter.getStartBlockId() + 1); |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 141 | } |
| 142 | else { |
| 143 | // set noEndTimeout timer |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 144 | process.noEndTime = time::steady_clock::now() + NOEND_TIMEOUT; |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | Name fetchName = name; |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 148 | fetchName.appendSegment(startBlockId); |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 149 | Interest interest(fetchName); |
| 150 | |
| 151 | ndn::util::SegmentFetcher::Options options; |
| 152 | options.initCwnd = initialCredit; |
| 153 | options.interestLifetime = m_interestLifetime; |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 154 | auto fetcher = ndn::util::SegmentFetcher::start(face, interest, m_validator, options); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 155 | fetcher->onError.connect([] (uint32_t, const auto& errorMsg) { |
| 156 | NDN_LOG_ERROR("Error: " << errorMsg); |
| 157 | }); |
| 158 | fetcher->afterSegmentValidated.connect([this, &fetcher, &processId] (const Data& data) { |
| 159 | onSegmentData(*fetcher, data, processId); |
| 160 | }); |
| 161 | fetcher->afterSegmentTimedOut.connect([this, &fetcher, &processId] { |
| 162 | onSegmentTimeout(*fetcher, processId); |
| 163 | }); |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void |
| 167 | WriteHandle::onSegmentData(ndn::util::SegmentFetcher& fetcher, const Data& data, ProcessId processId) |
| 168 | { |
| 169 | auto it = m_processes.find(processId); |
| 170 | if (it == m_processes.end()) { |
| 171 | fetcher.stop(); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | RepoCommandResponse& response = it->second.response; |
| 176 | |
| 177 | //insert data |
| 178 | if (storageHandle.insertData(data)) { |
| 179 | response.setInsertNum(response.getInsertNum() + 1); |
| 180 | } |
| 181 | |
| 182 | ProcessInfo& process = m_processes[processId]; |
| 183 | //read whether notime timeout |
| 184 | if (!response.hasEndBlockId()) { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 185 | auto noEndTime = process.noEndTime; |
| 186 | auto now = time::steady_clock::now(); |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 187 | |
| 188 | if (now > noEndTime) { |
| 189 | NDN_LOG_DEBUG("noEndtimeout: " << processId); |
| 190 | //StatusCode should be refreshed as 405 |
| 191 | response.setCode(405); |
| 192 | //schedule a delete event |
| 193 | deferredDeleteProcess(processId); |
| 194 | fetcher.stop(); |
| 195 | return; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | //read whether this process has total ends, if ends, remove control info from the maps |
| 200 | if (response.hasEndBlockId()) { |
| 201 | uint64_t nSegments = response.getEndBlockId() - response.getStartBlockId() + 1; |
| 202 | if (response.getInsertNum() >= nSegments) { |
| 203 | //All the data has been inserted, StatusCode is refreshed as 200 |
| 204 | response.setCode(200); |
| 205 | deferredDeleteProcess(processId); |
| 206 | fetcher.stop(); |
| 207 | return; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | void |
| 213 | WriteHandle::onSegmentTimeout(ndn::util::SegmentFetcher& fetcher, ProcessId processId) |
| 214 | { |
| 215 | NDN_LOG_DEBUG("SegTimeout"); |
| 216 | if (m_processes.count(processId) == 0) { |
| 217 | fetcher.stop(); |
| 218 | return; |
| 219 | } |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 223 | WriteHandle::processSegmentedInsertCommand(const Interest& interest, RepoCommandParameter& parameter, |
| 224 | const ndn::mgmt::CommandContinuation& done) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 225 | { |
| 226 | if (parameter.hasEndBlockId()) { |
| 227 | //normal fetch segment |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 228 | SegmentNo startBlockId = parameter.hasStartBlockId() ? parameter.getStartBlockId() : 0; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 229 | SegmentNo endBlockId = parameter.getEndBlockId(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 230 | if (startBlockId > endBlockId) { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 231 | done(negativeReply("Malformed Command", 403)); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 232 | return; |
| 233 | } |
| 234 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 235 | ProcessId processId = ndn::random::generateWord64(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 236 | ProcessInfo& process = m_processes[processId]; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 237 | RepoCommandResponse& response = process.response; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 238 | response.setCode(100); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 239 | response.setProcessId(processId); |
| 240 | response.setInsertNum(0); |
| 241 | response.setStartBlockId(startBlockId); |
| 242 | response.setEndBlockId(endBlockId); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 243 | response.setBody(response.wireEncode()); |
| 244 | done(response); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 245 | |
| 246 | //300 means data fetching is in progress |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 247 | response.setCode(300); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 248 | |
| 249 | segInit(processId, parameter); |
| 250 | } |
| 251 | else { |
| 252 | //no EndBlockId, so fetch FinalBlockId in data, if timeout, stop |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 253 | ProcessId processId = ndn::random::generateWord64(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 254 | ProcessInfo& process = m_processes[processId]; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 255 | RepoCommandResponse& response = process.response; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 256 | response.setCode(100); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 257 | response.setProcessId(processId); |
| 258 | response.setInsertNum(0); |
| 259 | response.setStartBlockId(parameter.getStartBlockId()); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 260 | response.setBody(response.wireEncode()); |
| 261 | done(response); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 262 | |
| 263 | //300 means data fetching is in progress |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 264 | response.setCode(300); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 265 | |
| 266 | segInit(processId, parameter); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | void |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 271 | WriteHandle::handleCheckCommand(const Name& prefix, const Interest& interest, |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 272 | const ndn::mgmt::ControlParameters& params, |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 273 | const ndn::mgmt::CommandContinuation& done) |
| 274 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 275 | const auto& repoParameter = dynamic_cast<const RepoCommandParameter&>(params); |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 276 | |
| 277 | //check whether this process exists |
| 278 | ProcessId processId = repoParameter.getProcessId(); |
| 279 | if (m_processes.count(processId) == 0) { |
| 280 | NDN_LOG_DEBUG("no such processId: " << processId); |
| 281 | done(negativeReply("No such this process is in progress", 404)); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | ProcessInfo& process = m_processes[processId]; |
| 286 | |
| 287 | RepoCommandResponse& response = process.response; |
| 288 | |
| 289 | //Check whether it is single data fetching |
| 290 | if (!response.hasStartBlockId() && !response.hasEndBlockId()) { |
| 291 | done(response); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | //read if noEndtimeout |
| 296 | if (!response.hasEndBlockId()) { |
| 297 | extendNoEndTime(process); |
| 298 | done(response); |
| 299 | return; |
| 300 | } |
| 301 | else { |
| 302 | done(response); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | void |
| 307 | WriteHandle::deferredDeleteProcess(ProcessId processId) |
| 308 | { |
Davide Pesavento | 8891c83 | 2019-03-20 23:20:35 -0400 | [diff] [blame] | 309 | scheduler.schedule(PROCESS_DELETE_TIME, [=] { deleteProcess(processId); }); |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 313 | WriteHandle::extendNoEndTime(ProcessInfo& process) |
| 314 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 315 | auto noEndTime = process.noEndTime; |
| 316 | auto now = time::steady_clock::now(); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 317 | RepoCommandResponse& response = process.response; |
| 318 | if (now > noEndTime) { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 319 | response.setCode(405); |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 320 | return; |
| 321 | } |
Davide Pesavento | 8891c83 | 2019-03-20 23:20:35 -0400 | [diff] [blame] | 322 | |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 323 | //extends noEndTime |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 324 | process.noEndTime = time::steady_clock::now() + NOEND_TIMEOUT; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 325 | } |
| 326 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 327 | RepoCommandResponse |
| 328 | WriteHandle::negativeReply(std::string text, int statusCode) |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 329 | { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 330 | RepoCommandResponse response(statusCode, text); |
| 331 | response.setBody(response.wireEncode()); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 332 | return response; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 335 | } // namespace repo |