Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 06807dc | 2017-09-19 15:52:43 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016-2017, Regents of the University of California, |
| 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 6 | * |
| 7 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 8 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 9 | * |
| 10 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 22 | * |
| 23 | * @author Andrea Tosatto |
| 24 | */ |
| 25 | |
| 26 | #include "discover-version-fixed.hpp" |
| 27 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 28 | namespace ndn { |
| 29 | namespace chunks { |
| 30 | |
| 31 | DiscoverVersionFixed::DiscoverVersionFixed(const Name& prefix, Face& face, const Options& options) |
| 32 | : Options(options) |
Davide Pesavento | 06807dc | 2017-09-19 15:52:43 -0400 | [diff] [blame] | 33 | , DiscoverVersion(prefix, face) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | |
| 37 | void |
| 38 | DiscoverVersionFixed::run() |
| 39 | { |
| 40 | Interest interest(m_prefix); |
| 41 | interest.setInterestLifetime(interestLifetime); |
| 42 | interest.setMustBeFresh(mustBeFresh); |
| 43 | interest.setMaxSuffixComponents(2); |
| 44 | interest.setMinSuffixComponents(2); |
| 45 | |
| 46 | expressInterest(interest, maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack); |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | DiscoverVersionFixed::handleData(const Interest& interest, const Data& data) |
| 51 | { |
| 52 | if (isVerbose) |
| 53 | std::cerr << "Data: " << data << std::endl; |
| 54 | |
| 55 | size_t segmentIndex = interest.getName().size(); |
| 56 | if (data.getName()[segmentIndex].isSegment()) { |
| 57 | if (isVerbose) |
| 58 | std::cerr << "Found data with the requested version: " << m_prefix[-1] << std::endl; |
| 59 | |
| 60 | this->emitSignal(onDiscoverySuccess, data); |
| 61 | } |
| 62 | else { |
| 63 | // data isn't a valid segment, add to the exclude list |
| 64 | m_strayExcludes.excludeOne(data.getName()[segmentIndex]); |
| 65 | Interest newInterest(interest); |
| 66 | newInterest.refreshNonce(); |
| 67 | newInterest.setExclude(m_strayExcludes); |
| 68 | |
| 69 | expressInterest(newInterest, maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } // namespace chunks |
| 74 | } // namespace ndn |