blob: e76ff17cb5c592887584a39bf7e6e7021c673294 [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/*
Davide Pesavento06807dc2017-09-19 15:52:43 -04003 * 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 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
Davide Pesavento06807dc2017-09-19 15:52:43 -040046 DiscoverVersionIterativeOptions(const Options& opts = Options())
47 : Options(opts)
Andrea Tosatto672b9a72016-01-05 16:18:20 +010048 {
49 }
50
51public:
Davide Pesavento06807dc2017-09-19 15:52:43 -040052 int maxRetriesAfterVersionFound{0}; ///< how many times to retry after a discoveryTimeout
53 time::milliseconds discoveryTimeout{300}; ///< timeout for version discovery
Andrea Tosatto672b9a72016-01-05 16:18:20 +010054};
55
56/**
57 * @brief Service for discovering the latest Data version in the iterative way
58 *
59 * Identifies the latest retrievable version published under the specified namespace
60 * (as specified by the Version marker).
61 *
62 * DiscoverVersionIterative declares the largest discovered version to be the latest after some
63 * Interest timeouts (i.e. failed retrieval after exclusion and retransmission). The number of
64 * timeouts are specified by the value of maxRetriesAfterVersionFound inside the iterative options.
65 *
66 * The received name component after version can be an invalid segment number, this component will
67 * be excluded in the next interests. In the unlikely case that there are too many excluded
68 * components such that the Interest cannot fit in ndn::MAX_NDN_PACKET_SIZE, the discovery
69 * procedure will throw Face::Error.
70 *
71 * DiscoverVersionIterative's user is notified once after identifying the latest retrievable
72 * version or on failure to find any version Data.
73 */
74class DiscoverVersionIterative : public DiscoverVersion, protected DiscoverVersionIterativeOptions
75{
76public:
77 typedef DiscoverVersionIterativeOptions Options;
78
79public:
80 /**
81 * @brief create a DiscoverVersionIterative service
82 */
83 DiscoverVersionIterative(const Name& prefix, Face& face, const Options& options);
84
85 /**
86 * @brief identify the latest Data version published.
87 */
88 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020089 run() final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010090
91private:
92 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020093 handleData(const Interest& interest, const Data& data) final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010094
95 void
Davide Pesavento25625ca2016-05-03 18:21:22 +020096 handleTimeout(const Interest& interest, const std::string& reason) final;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010097
98private:
99 uint64_t m_latestVersion;
100 shared_ptr<const Data> m_latestVersionData;
101 Exclude m_strayExcludes;
102 bool m_foundVersion;
103};
104
105} // namespace chunks
106} // namespace ndn
107
108#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_ITERATIVE_HPP