blob: 9428a06f3f2d30365c5221fefd1251452253ed63 [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
29#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_CONSUMER_HPP
30#define NDN_TOOLS_CHUNKS_CATCHUNKS_CONSUMER_HPP
31
32#include "pipeline-interests.hpp"
33#include "discover-version.hpp"
34
35#include <ndn-cxx/security/validator.hpp>
36
37namespace ndn {
38namespace chunks {
39
40/**
41 * @brief Segmented version consumer
42 *
43 * Discover the latest version of the data published under a specified prefix, and retrieve all the
44 * segments associated to that version. The segments are fetched in order and written to a
45 * user-specified stream in the same order.
46 */
47class Consumer : noncopyable
48{
49public:
50 class ApplicationNackError : public std::runtime_error
51 {
52 public:
53 explicit
54 ApplicationNackError(const Data& data)
55 : std::runtime_error("Application generated Nack: " + boost::lexical_cast<std::string>(data))
56 {
57 }
58 };
59
60 /**
61 * @brief Create the consumer
62 */
63 Consumer(Face& face, Validator& validator, bool isVerbose, std::ostream& os = std::cout);
64
65 /**
66 * @brief Run the consumer
67 */
68 void
69 run(DiscoverVersion& discover, PipelineInterests& pipeline);
70
71private:
72 void
73 runWithData(const Data& data);
74
75 void
76 onData(const Interest& interest, const Data& data);
77
78 void
79 onDataValidated(shared_ptr<const Data> data);
80
81 void
82 onFailure(const std::string& reason);
83
84PUBLIC_WITH_TESTS_ELSE_PRIVATE:
85 void
86 writeInOrderData();
87
88private:
89 Face& m_face;
90 Validator& m_validator;
91 PipelineInterests* m_pipeline;
92 uint64_t m_nextToPrint;
93 std::ostream& m_outputStream;
94 bool m_isVerbose;
95
96PUBLIC_WITH_TESTS_ELSE_PRIVATE:
97 std::map<uint64_t, shared_ptr<const Data>> m_bufferedData;
98};
99
100} // namespace chunks
101} // namespace ndn
102
103#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_CONSUMER_HPP