blob: c122d2fb66be3154c021187e99ebe19784171d58 [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/*
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -08003 * Copyright (c) 2016-2019, Regents of the University of California,
Davide Pesavento06807dc2017-09-19 15:52:43 -04004 * 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
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080055 // data name must end with a segment number, preceded by a version number
56 if (data.getName().size() >= 2 &&
57 data.getName()[-1].isSegment() &&
58 data.getName()[-2].isVersion()) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +010059 if (isVerbose)
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080060 std::cerr << "Found data with the requested version: " << data.getName()[-2] << std::endl;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010061
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080062 this->emitSignal(onDiscoverySuccess, data.getName().getPrefix(-1));
Andrea Tosatto672b9a72016-01-05 16:18:20 +010063 }
64 else {
65 // data isn't a valid segment, add to the exclude list
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080066 m_strayExcludes.excludeOne(data.getName()[-1]);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010067 Interest newInterest(interest);
68 newInterest.refreshNonce();
69 newInterest.setExclude(m_strayExcludes);
70
71 expressInterest(newInterest, maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack);
72 }
73}
74
75} // namespace chunks
76} // namespace ndn