blob: afacabda89ade7f8b49dc8dd1964a33142210262 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Klaus Schneider59ec95a2017-09-14 17:50:00 -07002/*
Davide Pesaventob3570c62022-02-19 19:19:00 -05003 * Copyright (c) 2016-2022, Regents of the University of California,
Davide Pesavento6f76afc2017-09-19 18:43:51 -04004 * 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
Davide Pesavento6f76afc2017-09-19 18:43:51 -040026 * @author Davide Pesavento
Klaus Schneider59ec95a2017-09-14 17:50:00 -070027 * @author Klaus Schneider
Andrea Tosatto672b9a72016-01-05 16:18:20 +010028 */
29
30#ifndef NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP
31#define NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP
32
33#include "core/common.hpp"
34
Davide Pesaventob3570c62022-02-19 19:19:00 -050035namespace ndn::chunks {
Andrea Tosatto672b9a72016-01-05 16:18:20 +010036
37/**
Davide Pesaventob61e3e22022-11-11 14:38:52 -050038 * @brief Segmented & versioned data publisher.
Andrea Tosatto672b9a72016-01-05 16:18:20 +010039 *
Davide Pesavento7c4246c2021-03-12 01:35:22 -050040 * Packetizes and publishes data from an input stream as `/prefix/<version>/<segment number>`.
41 * Unless another value is provided, the current time is used as the version number.
42 * The packet store always has at least one item, even when the input is empty.
Andrea Tosatto672b9a72016-01-05 16:18:20 +010043 */
44class Producer : noncopyable
45{
46public:
Davide Pesavento6f76afc2017-09-19 18:43:51 -040047 struct Options
48 {
49 security::SigningInfo signingInfo;
Davide Pesavento7c4246c2021-03-12 01:35:22 -050050 time::milliseconds freshnessPeriod = 10_s;
51 size_t maxSegmentSize = 8000;
Davide Pesavento6f76afc2017-09-19 18:43:51 -040052 bool isQuiet = false;
53 bool isVerbose = false;
54 bool wantShowVersion = false;
55 };
56
Andrea Tosatto672b9a72016-01-05 16:18:20 +010057 /**
Davide Pesaventob61e3e22022-11-11 14:38:52 -050058 * @brief Create the producer.
Davide Pesavento6f76afc2017-09-19 18:43:51 -040059 * @param prefix prefix used to publish data; if the last component is not a valid
60 * version number, the current system time is used as version number.
Andrea Tosatto672b9a72016-01-05 16:18:20 +010061 */
Davide Pesavento6f76afc2017-09-19 18:43:51 -040062 Producer(const Name& prefix, Face& face, KeyChain& keyChain, std::istream& is,
63 const Options& opts);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010064
65 /**
Davide Pesaventob61e3e22022-11-11 14:38:52 -050066 * @brief Run the producer.
Andrea Tosatto672b9a72016-01-05 16:18:20 +010067 */
68 void
69 run();
70
71private:
Andrea Tosatto672b9a72016-01-05 16:18:20 +010072 /**
Davide Pesaventob61e3e22022-11-11 14:38:52 -050073 * @brief Respond with a metadata packet containing the versioned content name.
Chavoosh Ghasemi79991a02019-01-28 21:22:31 -080074 */
Andrea Tosatto672b9a72016-01-05 16:18:20 +010075 void
Chavoosh Ghasemi79991a02019-01-28 21:22:31 -080076 processDiscoveryInterest(const Interest& interest);
77
78 /**
Davide Pesaventob61e3e22022-11-11 14:38:52 -050079 * @brief Respond with the requested segment of content.
Chavoosh Ghasemi79991a02019-01-28 21:22:31 -080080 */
81 void
82 processSegmentInterest(const Interest& interest);
Davide Pesavento6f76afc2017-09-19 18:43:51 -040083
Andrea Tosatto672b9a72016-01-05 16:18:20 +010084PUBLIC_WITH_TESTS_ELSE_PRIVATE:
85 std::vector<shared_ptr<Data>> m_store;
86
87private:
88 Name m_prefix;
89 Name m_versionedPrefix;
90 Face& m_face;
91 KeyChain& m_keyChain;
Davide Pesavento6f76afc2017-09-19 18:43:51 -040092 const Options m_options;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010093};
94
Davide Pesaventob3570c62022-02-19 19:19:00 -050095} // namespace ndn::chunks
Andrea Tosatto672b9a72016-01-05 16:18:20 +010096
97#endif // NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP