blob: 59652a63f91e8691277d858822db1f982a1e0bff [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Klaus Schneider7072e162017-09-16 13:43:00 -07002/*
3 * Copyright (c) 2016-2017, Regents of the University of California,
Andrea Tosatto672b9a72016-01-05 16:18:20 +01004 * 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 Wentao Shang
24 * @author Steve DiBenedetto
25 * @author Andrea Tosatto
Klaus Schneider7072e162017-09-16 13:43:00 -070026 * @author Klaus Schneider
Andrea Tosatto672b9a72016-01-05 16:18:20 +010027 */
28
29#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_ITERATIVE_HPP
30#define NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_ITERATIVE_HPP
31
32#include "discover-version.hpp"
33
34namespace ndn {
35namespace chunks {
36
37/**
38 * @brief Options for discover version iterative DiscoverVersionIterative
39 *
40 * The canonical name to use is DiscoverVersionIterative::Options
41 */
42class DiscoverVersionIterativeOptions : public virtual Options
43{
44public:
45 explicit
46 DiscoverVersionIterativeOptions(const Options& opt = Options())
47 : Options(opt)
Klaus Schneider7072e162017-09-16 13:43:00 -070048 , maxRetriesAfterVersionFound(0)
49 , discoveryTimeout(time::milliseconds(300))
Andrea Tosatto672b9a72016-01-05 16:18:20 +010050 {
51 }
52
53public:
Klaus Schneider7072e162017-09-16 13:43:00 -070054 int maxRetriesAfterVersionFound; // how many times to retry after a discoveryTimeout
55 time::milliseconds discoveryTimeout; // timeout for version discovery
Andrea Tosatto672b9a72016-01-05 16:18:20 +010056};
57
58/**
59 * @brief Service for discovering the latest Data version in the iterative way
60 *
61 * Identifies the latest retrievable version published under the specified namespace
62 * (as specified by the Version marker).
63 *
64 * DiscoverVersionIterative declares the largest discovered version to be the latest after some
65 * Interest timeouts (i.e. failed retrieval after exclusion and retransmission). The number of
66 * timeouts are specified by the value of maxRetriesAfterVersionFound inside the iterative options.
67 *
68 * The received name component after version can be an invalid segment number, this component will
69 * be excluded in the next interests. In the unlikely case that there are too many excluded
70 * components such that the Interest cannot fit in ndn::MAX_NDN_PACKET_SIZE, the discovery
71 * procedure will throw Face::Error.
72 *
73 * DiscoverVersionIterative's user is notified once after identifying the latest retrievable
74 * version or on failure to find any version Data.
75 */
76class DiscoverVersionIterative : public DiscoverVersion, protected DiscoverVersionIterativeOptions
77{
78public:
79 typedef DiscoverVersionIterativeOptions Options;
80
81public:
82 /**
83 * @brief create a DiscoverVersionIterative service
84 */
85 DiscoverVersionIterative(const Name& prefix, Face& face, const Options& options);
86
87 /**
88 * @brief identify the latest Data version published.
89 */
90 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020091 run() final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010092
93private:
94 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020095 handleData(const Interest& interest, const Data& data) final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010096
97 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020098 handleTimeout(const Interest& interest, const std::string& reason) final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010099
100private:
101 uint64_t m_latestVersion;
102 shared_ptr<const Data> m_latestVersionData;
103 Exclude m_strayExcludes;
104 bool m_foundVersion;
105};
106
107} // namespace chunks
108} // namespace ndn
109
110#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_ITERATIVE_HPP