blob: 6b763de6972b15e18081d02bd06d66cba37a5080 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2016, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
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
28#include <cmath>
29#include <boost/lexical_cast.hpp>
30
31namespace ndn {
32namespace chunks {
33
34DiscoverVersionFixed::DiscoverVersionFixed(const Name& prefix, Face& face, const Options& options)
35 : Options(options)
36 , DiscoverVersion(prefix, face, options)
37 , m_strayExcludes()
38{
39}
40
41void
42DiscoverVersionFixed::run()
43{
44 Interest interest(m_prefix);
45 interest.setInterestLifetime(interestLifetime);
46 interest.setMustBeFresh(mustBeFresh);
47 interest.setMaxSuffixComponents(2);
48 interest.setMinSuffixComponents(2);
49
50 expressInterest(interest, maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack);
51}
52
53void
54DiscoverVersionFixed::handleData(const Interest& interest, const Data& data)
55{
56 if (isVerbose)
57 std::cerr << "Data: " << data << std::endl;
58
59 size_t segmentIndex = interest.getName().size();
60 if (data.getName()[segmentIndex].isSegment()) {
61 if (isVerbose)
62 std::cerr << "Found data with the requested version: " << m_prefix[-1] << std::endl;
63
64 this->emitSignal(onDiscoverySuccess, data);
65 }
66 else {
67 // data isn't a valid segment, add to the exclude list
68 m_strayExcludes.excludeOne(data.getName()[segmentIndex]);
69 Interest newInterest(interest);
70 newInterest.refreshNonce();
71 newInterest.setExclude(m_strayExcludes);
72
73 expressInterest(newInterest, maxRetriesOnTimeoutOrNack, maxRetriesOnTimeoutOrNack);
74 }
75}
76
77} // namespace chunks
78} // namespace ndn