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