blob: 5d434f0c79adaf74074d431e17bfac15a16a94db [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento06807dc2017-09-19 15:52:43 -04002/*
3 * Copyright (c) 2016-2017, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Andrea Tosatto672b9a72016-01-05 16:18:20 +01006 *
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 Tosatto672b9a72016-01-05 16:18:20 +010028namespace ndn {
29namespace chunks {
30
31DiscoverVersionFixed::DiscoverVersionFixed(const Name& prefix, Face& face, const Options& options)
32 : Options(options)
Davide Pesavento06807dc2017-09-19 15:52:43 -040033 , DiscoverVersion(prefix, face)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010034{
35}
36
37void
38DiscoverVersionFixed::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
49void
50DiscoverVersionFixed::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