Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 1cf5c43 | 2017-01-13 23:22:15 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, Regents of the University of California. |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -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 | 8811b35 | 2013-01-02 12:51:15 -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 | 8811b35 | 2013-01-02 12:51:15 -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 | 8811b35 | 2013-01-02 12:51:15 -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 | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 21 | #include "fetch-manager.hpp" |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 22 | #include "core/logging.hpp" |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 23 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 24 | #include <ndn-cxx/face.hpp> |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace chronoshare { |
Alexander Afanasyev | fc72036 | 2013-01-24 21:49:48 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 1cf5c43 | 2017-01-13 23:22:15 -0800 | [diff] [blame] | 29 | _LOG_INIT(FetchManager); |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 30 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 31 | // The disposer object function |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 32 | struct fetcher_disposer |
| 33 | { |
| 34 | void |
| 35 | operator()(Fetcher* delete_this) |
| 36 | { |
| 37 | delete delete_this; |
| 38 | } |
| 39 | }; |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 40 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 41 | FetchManager::FetchManager(Face& face, const Mapping& mapping, const Name& broadcastForwardingHint, |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 42 | uint32_t parallelFetches, // = 3 |
| 43 | const SegmentCallback& defaultSegmentCallback, |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 44 | const FinishCallback& defaultFinishCallback, const FetchTaskDbPtr& taskDb) |
| 45 | : m_face(face) |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 46 | , m_mapping(mapping) |
| 47 | , m_maxParallelFetches(parallelFetches) |
| 48 | , m_currentParallelFetches(0) |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 49 | , m_scheduler(m_face.getIoService()) |
| 50 | , m_scheduledFetchesEvent(m_scheduler) |
Zhenkai Zhu | a014738 | 2013-01-29 15:57:27 -0800 | [diff] [blame] | 51 | , m_defaultSegmentCallback(defaultSegmentCallback) |
| 52 | , m_defaultFinishCallback(defaultFinishCallback) |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 53 | , m_taskDb(taskDb) |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 54 | , m_broadcastHint(broadcastForwardingHint) |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 55 | , m_ioService(m_face.getIoService()) |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 56 | { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 57 | // no need to check to often. if needed, will be rescheduled |
| 58 | m_scheduledFetchesEvent = |
| 59 | m_scheduler.scheduleEvent(time::seconds(300), bind(&FetchManager::ScheduleFetches, this)); |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 60 | |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 61 | // resume un-finished fetches if there is any |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 62 | if (m_taskDb) { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 63 | m_taskDb->foreachTask( |
| 64 | [this](const Name& deviceName, const Name& baseName, uint64_t minSeqNo, uint64_t maxSeqNo, |
| 65 | int priority) { this->Enqueue(deviceName, baseName, minSeqNo, maxSeqNo, priority); }); |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 66 | } |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 67 | } |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 68 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 69 | FetchManager::~FetchManager() |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 70 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 71 | m_fetchList.clear_and_dispose(fetcher_disposer()); |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 72 | } |
Alexander Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 73 | |
Zhenkai Zhu | a014738 | 2013-01-29 15:57:27 -0800 | [diff] [blame] | 74 | // Enqueue using default callbacks |
| 75 | void |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 76 | FetchManager::Enqueue(const Name& deviceName, const Name& baseName, uint64_t minSeqNo, |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 77 | uint64_t maxSeqNo, int priority) |
Zhenkai Zhu | a014738 | 2013-01-29 15:57:27 -0800 | [diff] [blame] | 78 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 79 | Enqueue(deviceName, baseName, m_defaultSegmentCallback, m_defaultFinishCallback, minSeqNo, |
| 80 | maxSeqNo, priority); |
Zhenkai Zhu | a014738 | 2013-01-29 15:57:27 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 83 | void |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 84 | FetchManager::Enqueue(const Name& deviceName, const Name& baseName, |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 85 | const SegmentCallback& segmentCallback, const FinishCallback& finishCallback, |
| 86 | uint64_t minSeqNo, uint64_t maxSeqNo, int priority /*PRIORITY_NORMAL*/) |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 87 | { |
Zhenkai Zhu | 454bae2 | 2013-01-24 19:27:54 -0800 | [diff] [blame] | 88 | // Assumption for the following code is minSeqNo <= maxSeqNo |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 89 | if (minSeqNo > maxSeqNo) { |
Zhenkai Zhu | 454bae2 | 2013-01-24 19:27:54 -0800 | [diff] [blame] | 90 | return; |
| 91 | } |
| 92 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 93 | // we may need to guarantee that LookupLocator will gives an answer and not throw exception... |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 94 | Name forwardingHint; |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 95 | forwardingHint = m_mapping(deviceName); |
Alexander Afanasyev | 21a166e | 2013-01-20 16:04:41 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 97 | if (m_taskDb) { |
| 98 | m_taskDb->addTask(deviceName, baseName, minSeqNo, maxSeqNo, priority); |
| 99 | } |
Zhenkai Zhu | da68688 | 2013-01-29 22:32:24 -0800 | [diff] [blame] | 100 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 101 | std::unique_lock<std::mutex> lock(m_parellelFetchMutex); |
Alexander Afanasyev | bc8bf23 | 2013-01-29 11:19:17 -0800 | [diff] [blame] | 102 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 103 | _LOG_TRACE("++++ Create fetcher: " << baseName); |
| 104 | Fetcher* fetcher = |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 105 | new Fetcher(m_face, segmentCallback, finishCallback, |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 106 | bind(&FetchManager::DidFetchComplete, this, _1, _2, _3), |
| 107 | bind(&FetchManager::DidNoDataTimeout, this, _1), deviceName, baseName, minSeqNo, |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 108 | maxSeqNo, time::seconds(30), forwardingHint); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 109 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 110 | switch (priority) { |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 111 | case PRIORITY_HIGH: |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 112 | _LOG_TRACE("++++ Push front fetcher: " << fetcher->GetName()); |
| 113 | m_fetchList.push_front(*fetcher); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 114 | break; |
| 115 | |
| 116 | case PRIORITY_NORMAL: |
| 117 | default: |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 118 | _LOG_TRACE("++++ Push back fetcher: " << fetcher->GetName()); |
| 119 | m_fetchList.push_back(*fetcher); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 120 | break; |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 121 | } |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 122 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 123 | _LOG_DEBUG("++++ Reschedule fetcher task"); |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 124 | m_scheduledFetchesEvent = |
| 125 | m_scheduler.scheduleEvent(time::seconds(0), bind(&FetchManager::ScheduleFetches, this)); |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 126 | } |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 127 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 128 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 129 | FetchManager::ScheduleFetches() |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 130 | { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 131 | std::unique_lock<std::mutex> lock(m_parellelFetchMutex); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 132 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 133 | auto currentTime = time::steady_clock::now(); |
| 134 | auto nextSheduleCheck = currentTime + time::seconds(300); // no reason to have anything, but just in case |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 136 | for (FetchList::iterator item = m_fetchList.begin(); |
| 137 | m_currentParallelFetches < m_maxParallelFetches && item != m_fetchList.end(); |
| 138 | item++) { |
| 139 | if (item->IsActive()) { |
| 140 | _LOG_DEBUG("Item is active"); |
| 141 | continue; |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 142 | } |
Alexander Afanasyev | f975623 | 2013-01-28 16:42:20 -0800 | [diff] [blame] | 143 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 144 | if (item->IsTimedWait()) { |
| 145 | _LOG_DEBUG("Item is in timed-wait"); |
| 146 | continue; |
| 147 | } |
| 148 | |
| 149 | if (currentTime < item->GetNextScheduledRetry()) { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 150 | if (item->GetNextScheduledRetry() < nextSheduleCheck) { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 151 | nextSheduleCheck = item->GetNextScheduledRetry(); |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 152 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 153 | |
| 154 | _LOG_DEBUG("Item is delayed"); |
| 155 | continue; |
| 156 | } |
| 157 | |
| 158 | _LOG_DEBUG("Start fetching of " << item->GetName()); |
| 159 | |
| 160 | m_currentParallelFetches++; |
| 161 | _LOG_TRACE("++++ RESTART PIPELINE: " << item->GetName()); |
| 162 | item->RestartPipeline(); |
| 163 | } |
| 164 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 165 | m_scheduledFetchesEvent = m_scheduler.scheduleEvent(nextSheduleCheck - currentTime, |
| 166 | bind(&FetchManager::ScheduleFetches, this)); |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 169 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 170 | FetchManager::DidNoDataTimeout(Fetcher& fetcher) |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 171 | { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 172 | _LOG_DEBUG("No data timeout for " << fetcher.GetName() << " with forwarding hint: " |
| 173 | << fetcher.GetForwardingHint()); |
Alexander Afanasyev | ff8d9dc | 2013-01-26 00:45:08 -0800 | [diff] [blame] | 174 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 175 | { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 176 | std::unique_lock<std::mutex> lock(m_parellelFetchMutex); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 177 | m_currentParallelFetches--; |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 178 | // no need to do anything with the m_fetchList |
| 179 | } |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 180 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 181 | if (fetcher.GetForwardingHint().size() == 0) { |
| 182 | // will be tried initially and again after empty forwarding hint |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 183 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 184 | /// @todo Handle potential exception |
| 185 | Name forwardingHint; |
| 186 | forwardingHint = m_mapping(fetcher.GetDeviceName()); |
Alexander Afanasyev | 84894d3 | 2013-02-08 22:27:12 -0800 | [diff] [blame] | 187 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 188 | if (forwardingHint.size() == 0) { |
| 189 | // make sure that we will try broadcast forwarding hint eventually |
| 190 | fetcher.SetForwardingHint(m_broadcastHint); |
Alexander Afanasyev | 84894d3 | 2013-02-08 22:27:12 -0800 | [diff] [blame] | 191 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 192 | else { |
| 193 | fetcher.SetForwardingHint(forwardingHint); |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 194 | } |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 195 | } |
| 196 | else if (fetcher.GetForwardingHint() == m_broadcastHint) { |
| 197 | // will be tried after broadcast forwarding hint |
| 198 | fetcher.SetForwardingHint(Name("/")); |
| 199 | } |
| 200 | else { |
| 201 | // will be tried after normal forwarding hint |
| 202 | fetcher.SetForwardingHint(m_broadcastHint); |
| 203 | } |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 204 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 205 | time::seconds delay = fetcher.GetRetryPause(); |
| 206 | if (delay < time::seconds(1)) // first time |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 207 | { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 208 | delay = time::seconds(1); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 209 | } |
| 210 | else { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 211 | delay = std::min(2 * delay, time::seconds(300)); // 5 minutes max |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 212 | } |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 213 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 214 | fetcher.SetRetryPause(delay); |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 215 | fetcher.SetNextScheduledRetry(time::steady_clock::now() + time::seconds(delay)); |
Alexander Afanasyev | f975623 | 2013-01-28 16:42:20 -0800 | [diff] [blame] | 216 | |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 217 | m_scheduledFetchesEvent = m_scheduler.scheduleEvent(time::seconds(0), bind(&FetchManager::ScheduleFetches, this)); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 221 | FetchManager::DidFetchComplete(Fetcher& fetcher, const Name& deviceName, const Name& baseName) |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 222 | { |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 223 | { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 224 | std::unique_lock<std::mutex> lock(m_parellelFetchMutex); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 225 | m_currentParallelFetches--; |
Alexander Afanasyev | 1d1cc83 | 2013-02-05 20:03:36 -0800 | [diff] [blame] | 226 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 227 | if (m_taskDb) { |
| 228 | m_taskDb->deleteTask(deviceName, baseName); |
| 229 | } |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 230 | } |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 231 | |
Zhenkai Zhu | 354d46d | 2013-02-06 13:49:48 -0800 | [diff] [blame] | 232 | // like TCP timed-wait |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 233 | m_scheduler.scheduleEvent(time::seconds(10), bind(&FetchManager::TimedWait, this, ref(fetcher))); |
| 234 | m_scheduledFetchesEvent = m_scheduler.scheduleEvent(time::seconds(0), bind(&FetchManager::ScheduleFetches, this)); |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 235 | } |
Zhenkai Zhu | 354d46d | 2013-02-06 13:49:48 -0800 | [diff] [blame] | 236 | |
| 237 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 238 | FetchManager::TimedWait(Fetcher& fetcher) |
Zhenkai Zhu | 354d46d | 2013-02-06 13:49:48 -0800 | [diff] [blame] | 239 | { |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 240 | std::unique_lock<std::mutex> lock(m_parellelFetchMutex); |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 241 | _LOG_TRACE("+++++ removing fetcher: " << fetcher.GetName()); |
| 242 | m_fetchList.erase_and_dispose(FetchList::s_iterator_to(fetcher), fetcher_disposer()); |
Zhenkai Zhu | 354d46d | 2013-02-06 13:49:48 -0800 | [diff] [blame] | 243 | } |
Lijing Wang | a697cf2 | 2016-12-25 14:44:22 -0800 | [diff] [blame] | 244 | |
| 245 | } // namespace chronoshare |
| 246 | } // namespace ndn |