Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016, Regents of the University of California. |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 11 | * ChronoShare 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 General Public License for more details. |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "fetcher.h" |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 22 | #include "ccnx-pco.h" |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 23 | #include "fetch-manager.h" |
Alexander Afanasyev | 678f350 | 2013-01-23 17:09:37 -0800 | [diff] [blame] | 24 | #include "logging.h" |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 25 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 26 | #include <boost/date_time/posix_time/posix_time.hpp> |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 27 | #include <boost/make_shared.hpp> |
| 28 | #include <boost/ref.hpp> |
| 29 | #include <boost/throw_exception.hpp> |
| 30 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 31 | INIT_LOGGER("Fetcher"); |
Alexander Afanasyev | 678f350 | 2013-01-23 17:09:37 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 33 | using namespace boost; |
| 34 | using namespace std; |
Alexander Afanasyev | 1dd37ed | 2013-08-14 18:08:09 -0700 | [diff] [blame] | 35 | using namespace Ndnx; |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 36 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 37 | Fetcher::Fetcher(Ccnx::CcnxWrapperPtr ccnx, ExecutorPtr executor, |
| 38 | const SegmentCallback& segmentCallback, const FinishCallback& finishCallback, |
| 39 | OnFetchCompleteCallback onFetchComplete, OnFetchFailedCallback onFetchFailed, |
| 40 | const Ccnx::Name& deviceName, const Ccnx::Name& name, int64_t minSeqNo, |
| 41 | int64_t maxSeqNo, |
| 42 | boost::posix_time::time_duration timeout /* = boost::posix_time::seconds (30)*/, |
| 43 | const Ccnx::Name& forwardingHint /* = Ccnx::Name ()*/) |
| 44 | : m_ccnx(ccnx) |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 46 | , m_segmentCallback(segmentCallback) |
| 47 | , m_onFetchComplete(onFetchComplete) |
| 48 | , m_onFetchFailed(onFetchFailed) |
| 49 | , m_finishCallback(finishCallback) |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 50 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 51 | , m_active(false) |
| 52 | , m_timedwait(false) |
| 53 | , m_name(name) |
| 54 | , m_deviceName(deviceName) |
| 55 | , m_forwardingHint(forwardingHint) |
| 56 | , m_maximumNoActivityPeriod(timeout) |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 57 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 58 | , m_minSendSeqNo(minSeqNo - 1) |
| 59 | , m_maxInOrderRecvSeqNo(minSeqNo - 1) |
| 60 | , m_minSeqNo(minSeqNo) |
| 61 | , m_maxSeqNo(maxSeqNo) |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 63 | , m_pipeline(6) // initial "congestion window" |
| 64 | , m_activePipeline(0) |
| 65 | , m_retryPause(0) |
| 66 | , m_nextScheduledRetry(date_time::second_clock<boost::posix_time::ptime>::universal_time()) |
| 67 | , m_executor(executor) // must be 1 |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 68 | { |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 71 | Fetcher::~Fetcher() |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 72 | { |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 73 | } |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 74 | |
| 75 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 76 | Fetcher::RestartPipeline() |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 77 | { |
| 78 | m_active = true; |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 79 | m_minSendSeqNo = m_maxInOrderRecvSeqNo; |
Alexander Afanasyev | 650ba28 | 2013-01-20 20:14:06 -0800 | [diff] [blame] | 80 | // cout << "Restart: " << m_minSendSeqNo << endl; |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 81 | m_lastPositiveActivity = date_time::second_clock<boost::posix_time::ptime>::universal_time(); |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 82 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 83 | m_executor->execute(bind(&Fetcher::FillPipeline, this)); |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 87 | Fetcher::SetForwardingHint(const Ccnx::Name& forwardingHint) |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 88 | { |
| 89 | m_forwardingHint = forwardingHint; |
| 90 | } |
| 91 | |
| 92 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 93 | Fetcher::FillPipeline() |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 94 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 95 | for (; m_minSendSeqNo < m_maxSeqNo && m_activePipeline < m_pipeline; m_minSendSeqNo++) { |
| 96 | unique_lock<mutex> lock(m_seqNoMutex); |
Alexander Afanasyev | 2ec2c38 | 2013-01-29 20:09:00 -0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 98 | if (m_outOfOrderRecvSeqNo.find(m_minSendSeqNo + 1) != m_outOfOrderRecvSeqNo.end()) |
| 99 | continue; |
Alexander Afanasyev | 650ba28 | 2013-01-20 20:14:06 -0800 | [diff] [blame] | 100 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 101 | if (m_inActivePipeline.find(m_minSendSeqNo + 1) != m_inActivePipeline.end()) |
| 102 | continue; |
Alexander Afanasyev | cfd5dfc | 2013-01-28 22:21:31 -0800 | [diff] [blame] | 103 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 104 | m_inActivePipeline.insert(m_minSendSeqNo + 1); |
Alexander Afanasyev | cfd5dfc | 2013-01-28 22:21:31 -0800 | [diff] [blame] | 105 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 106 | _LOG_DEBUG(" >>> i " << Name(m_forwardingHint)(m_name) << ", seq = " << (m_minSendSeqNo + 1)); |
Alexander Afanasyev | 678f350 | 2013-01-23 17:09:37 -0800 | [diff] [blame] | 107 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 108 | // cout << ">>> " << m_minSendSeqNo+1 << endl; |
| 109 | m_ccnx->sendInterest(Name(m_forwardingHint)(m_name)(m_minSendSeqNo + 1), |
| 110 | Closure(bind(&Fetcher::OnData, this, m_minSendSeqNo + 1, _1, _2), |
| 111 | bind(&Fetcher::OnTimeout, this, m_minSendSeqNo + 1, _1, _2, _3)), |
| 112 | Selectors().interestLifetime(1)); // Alex: this lifetime should be changed to RTO |
| 113 | _LOG_DEBUG(" >>> i ok"); |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 115 | m_activePipeline++; |
| 116 | } |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 117 | } |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 118 | |
| 119 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 120 | Fetcher::OnData(uint64_t seqno, const Ccnx::Name& name, PcoPtr data) |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 121 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 122 | m_executor->execute(bind(&Fetcher::OnData_Execute, this, seqno, name, data)); |
Alexander Afanasyev | ddc283c | 2013-01-28 23:11:20 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 126 | Fetcher::OnData_Execute(uint64_t seqno, Ccnx::Name name, Ccnx::PcoPtr data) |
Alexander Afanasyev | ddc283c | 2013-01-28 23:11:20 -0800 | [diff] [blame] | 127 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 128 | _LOG_DEBUG(" <<< d " << name.getPartialName(0, name.size() - 1) << ", seq = " << seqno); |
Alexander Afanasyev | fc72036 | 2013-01-24 21:49:48 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 130 | if (m_forwardingHint == Name()) { |
Zhenkai Zhu | d5d99be | 2013-03-13 19:15:56 -0700 | [diff] [blame] | 131 | // TODO: check verified!!!! |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 132 | if (true) { |
| 133 | if (!m_segmentCallback.empty()) { |
| 134 | m_segmentCallback(m_deviceName, m_name, seqno, data); |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 135 | } |
Zhenkai Zhu | 5957c0d | 2013-02-08 13:47:52 -0800 | [diff] [blame] | 136 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 137 | else { |
Zhenkai Zhu | 5957c0d | 2013-02-08 13:47:52 -0800 | [diff] [blame] | 138 | _LOG_ERROR("Can not verify signature content. Name = " << data->name()); |
| 139 | // probably needs to do more in the future |
| 140 | } |
Zhenkai Zhu | 3d1beca | 2013-01-23 14:55:32 -0800 | [diff] [blame] | 141 | // we don't have to tell FetchManager about this |
| 142 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 143 | else { |
| 144 | // in this case we don't care whether "data" is verified, in fact, we expect it is unverified |
| 145 | try { |
| 146 | PcoPtr pco = make_shared<ParsedContentObject>(*data->contentPtr()); |
Zhenkai Zhu | 79264a4 | 2013-02-07 21:49:42 -0800 | [diff] [blame] | 147 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 148 | // we need to verify this pco and apply callback only when verified |
| 149 | // TODO: check verified !!! |
| 150 | if (true) { |
| 151 | if (!m_segmentCallback.empty()) { |
| 152 | m_segmentCallback(m_deviceName, m_name, seqno, pco); |
Zhenkai Zhu | 5957c0d | 2013-02-08 13:47:52 -0800 | [diff] [blame] | 153 | } |
Alexander Afanasyev | 66f4c49 | 2013-01-20 23:32:50 -0800 | [diff] [blame] | 154 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 155 | else { |
| 156 | _LOG_ERROR("Can not verify signature content. Name = " << pco->name()); |
| 157 | // probably needs to do more in the future |
| 158 | } |
Alexander Afanasyev | 66f4c49 | 2013-01-20 23:32:50 -0800 | [diff] [blame] | 159 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 160 | catch (MisformedContentObjectException& e) { |
| 161 | cerr << "MisformedContentObjectException..." << endl; |
| 162 | // no idea what should do... |
| 163 | // let's ignore for now |
| 164 | } |
| 165 | } |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 166 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 167 | m_activePipeline--; |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 168 | m_lastPositiveActivity = date_time::second_clock<boost::posix_time::ptime>::universal_time(); |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 169 | |
Yingdi Yu | f0b3de3 | 2013-07-11 12:59:00 -0700 | [diff] [blame] | 170 | { |
| 171 | unique_lock<mutex> lock (m_pipelineMutex); |
| 172 | if(m_slowStart){ |
| 173 | m_pipeline++; |
| 174 | if(m_pipeline == m_threshold) |
| 175 | m_slowStart = false; |
| 176 | } |
| 177 | else{ |
| 178 | m_roundCount++; |
| 179 | _LOG_DEBUG ("roundCount: " << m_roundCount); |
| 180 | if(m_roundCount == m_pipeline){ |
| 181 | m_pipeline++; |
| 182 | m_roundCount = 0; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | _LOG_DEBUG ("slowStart: " << boolalpha << m_slowStart << " pipeline: " << m_pipeline << " threshold: " << m_threshold); |
| 188 | |
| 189 | |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 190 | //////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 191 | unique_lock<mutex> lock(m_seqNoMutex); |
Alexander Afanasyev | 2ec2c38 | 2013-01-29 20:09:00 -0800 | [diff] [blame] | 192 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 193 | m_outOfOrderRecvSeqNo.insert(seqno); |
| 194 | m_inActivePipeline.erase(seqno); |
| 195 | _LOG_DEBUG("Total segments received: " << m_outOfOrderRecvSeqNo.size()); |
| 196 | set<int64_t>::iterator inOrderSeqNo = m_outOfOrderRecvSeqNo.begin(); |
| 197 | for (; inOrderSeqNo != m_outOfOrderRecvSeqNo.end(); inOrderSeqNo++) { |
| 198 | _LOG_TRACE("Checking " << *inOrderSeqNo << " and " << m_maxInOrderRecvSeqNo + 1); |
| 199 | if (*inOrderSeqNo == m_maxInOrderRecvSeqNo + 1) { |
| 200 | m_maxInOrderRecvSeqNo = *inOrderSeqNo; |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 201 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 202 | else if (*inOrderSeqNo < m_maxInOrderRecvSeqNo + 1) // not possible anymore, but just in case |
| 203 | { |
| 204 | continue; |
| 205 | } |
| 206 | else |
| 207 | break; |
| 208 | } |
| 209 | m_outOfOrderRecvSeqNo.erase(m_outOfOrderRecvSeqNo.begin(), inOrderSeqNo); |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 210 | //////////////////////////////////////////////////////////////////////////// |
| 211 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 212 | _LOG_TRACE("Max in order received: " << m_maxInOrderRecvSeqNo |
| 213 | << ", max seqNo to request: " << m_maxSeqNo); |
Alexander Afanasyev | cfd5dfc | 2013-01-28 22:21:31 -0800 | [diff] [blame] | 214 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 215 | if (m_maxInOrderRecvSeqNo == m_maxSeqNo) { |
| 216 | _LOG_TRACE("Fetch finished: " << m_name); |
| 217 | m_active = false; |
| 218 | // invoke callback |
| 219 | if (!m_finishCallback.empty()) { |
| 220 | _LOG_TRACE("Notifying callback"); |
| 221 | m_finishCallback(m_deviceName, m_name); |
| 222 | } |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame] | 223 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 224 | // tell FetchManager that we have finish our job |
| 225 | // m_onFetchComplete (*this); |
| 226 | // using executor, so we won't be deleted if there is scheduled FillPipeline call |
| 227 | if (!m_onFetchComplete.empty()) { |
| 228 | m_timedwait = true; |
| 229 | m_executor->execute(bind(m_onFetchComplete, ref(*this), m_deviceName, m_name)); |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 230 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 231 | } |
| 232 | else { |
| 233 | m_executor->execute(bind(&Fetcher::FillPipeline, this)); |
| 234 | } |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Zhenkai Zhu | ff4fa8a | 2013-01-28 22:02:40 -0800 | [diff] [blame] | 237 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 238 | Fetcher::OnTimeout(uint64_t seqno, const Ccnx::Name& name, const Closure& closure, Selectors selectors) |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 239 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 240 | _LOG_DEBUG(this << ", " << m_executor.get()); |
| 241 | m_executor->execute(bind(&Fetcher::OnTimeout_Execute, this, seqno, name, closure, selectors)); |
Alexander Afanasyev | ddc283c | 2013-01-28 23:11:20 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 245 | Fetcher::OnTimeout_Execute(uint64_t seqno, Ccnx::Name name, Ccnx::Closure closure, |
| 246 | Ccnx::Selectors selectors) |
Alexander Afanasyev | ddc283c | 2013-01-28 23:11:20 -0800 | [diff] [blame] | 247 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 248 | _LOG_DEBUG(" <<< :( timeout " << name.getPartialName(0, name.size() - 1) << ", seq = " << seqno); |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 249 | |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 250 | // cout << "Fetcher::OnTimeout: " << name << endl; |
| 251 | // cout << "Last: " << m_lastPositiveActivity << ", config: " << m_maximumNoActivityPeriod |
| 252 | // << ", now: " << date_time::second_clock<boost::posix_time::ptime>::universal_time() |
| 253 | // << ", oldest: " << (date_time::second_clock<boost::posix_time::ptime>::universal_time() - m_maximumNoActivityPeriod) << endl; |
| 254 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 255 | if (m_lastPositiveActivity < (date_time::second_clock<boost::posix_time::ptime>::universal_time() - |
| 256 | m_maximumNoActivityPeriod)) { |
| 257 | bool done = false; |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 258 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 259 | unique_lock<mutex> lock(m_seqNoMutex); |
| 260 | m_inActivePipeline.erase(seqno); |
| 261 | m_activePipeline--; |
Alexander Afanasyev | 2ec2c38 | 2013-01-29 20:09:00 -0800 | [diff] [blame] | 262 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 263 | if (m_activePipeline == 0) { |
| 264 | done = true; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | if (done) { |
| 269 | { |
| 270 | unique_lock<mutex> lock(m_seqNoMutex); |
| 271 | _LOG_DEBUG("Telling that fetch failed"); |
| 272 | _LOG_DEBUG("Active pipeline size should be zero: " << m_inActivePipeline.size()); |
Alexander Afanasyev | 2ec2c38 | 2013-01-29 20:09:00 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 275 | m_active = false; |
| 276 | if (!m_onFetchFailed.empty()) { |
| 277 | m_onFetchFailed(ref(*this)); |
Yingdi Yu | f0b3de3 | 2013-07-11 12:59:00 -0700 | [diff] [blame] | 278 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 279 | // this is not valid anymore, but we still should be able finish work |
Alexander Afanasyev | ff8d9dc | 2013-01-26 00:45:08 -0800 | [diff] [blame] | 280 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 281 | } |
| 282 | else { |
| 283 | _LOG_DEBUG("Asking to reexpress seqno: " << seqno); |
| 284 | m_ccnx->sendInterest(name, closure, selectors); |
| 285 | } |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 286 | } |