blob: 8beb2fb784adf0562165d12d95d4fb05cced3a4d [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 Wentao Shang
24 * @author Steve DiBenedetto
25 * @author Andrea Tosatto
26 */
27
28#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_ITERATIVE_HPP
29#define NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_ITERATIVE_HPP
30
31#include "discover-version.hpp"
32
33namespace ndn {
34namespace chunks {
35
36/**
37 * @brief Options for discover version iterative DiscoverVersionIterative
38 *
39 * The canonical name to use is DiscoverVersionIterative::Options
40 */
41class DiscoverVersionIterativeOptions : public virtual Options
42{
43public:
44 explicit
45 DiscoverVersionIterativeOptions(const Options& opt = Options())
46 : Options(opt)
47 , maxRetriesAfterVersionFound(1)
48 {
49 }
50
51public:
52 int maxRetriesAfterVersionFound; // used only in timeout handling
53};
54
55/**
56 * @brief Service for discovering the latest Data version in the iterative way
57 *
58 * Identifies the latest retrievable version published under the specified namespace
59 * (as specified by the Version marker).
60 *
61 * DiscoverVersionIterative declares the largest discovered version to be the latest after some
62 * Interest timeouts (i.e. failed retrieval after exclusion and retransmission). The number of
63 * timeouts are specified by the value of maxRetriesAfterVersionFound inside the iterative options.
64 *
65 * The received name component after version can be an invalid segment number, this component will
66 * be excluded in the next interests. In the unlikely case that there are too many excluded
67 * components such that the Interest cannot fit in ndn::MAX_NDN_PACKET_SIZE, the discovery
68 * procedure will throw Face::Error.
69 *
70 * DiscoverVersionIterative's user is notified once after identifying the latest retrievable
71 * version or on failure to find any version Data.
72 */
73class DiscoverVersionIterative : public DiscoverVersion, protected DiscoverVersionIterativeOptions
74{
75public:
76 typedef DiscoverVersionIterativeOptions Options;
77
78public:
79 /**
80 * @brief create a DiscoverVersionIterative service
81 */
82 DiscoverVersionIterative(const Name& prefix, Face& face, const Options& options);
83
84 /**
85 * @brief identify the latest Data version published.
86 */
87 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020088 run() final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010089
90private:
91 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020092 handleData(const Interest& interest, const Data& data) final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010093
94 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020095 handleTimeout(const Interest& interest, const std::string& reason) final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010096
97private:
98 uint64_t m_latestVersion;
99 shared_ptr<const Data> m_latestVersionData;
100 Exclude m_strayExcludes;
101 bool m_foundVersion;
102};
103
104} // namespace chunks
105} // namespace ndn
106
107#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_ITERATIVE_HPP