Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Klaus Schneider | 59ec95a | 2017-09-14 17:50:00 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 3 | * Copyright (c) 2016-2024, Regents of the University of California, |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 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 |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 26 | * @author Davide Pesavento |
Klaus Schneider | 59ec95a | 2017-09-14 17:50:00 -0700 | [diff] [blame] | 27 | * @author Klaus Schneider |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 28 | */ |
| 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 Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 35 | #include <ndn-cxx/face.hpp> |
| 36 | #include <ndn-cxx/security/key-chain.hpp> |
| 37 | |
| 38 | #include <vector> |
| 39 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 40 | namespace ndn::chunks { |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 41 | |
| 42 | /** |
Davide Pesavento | b61e3e2 | 2022-11-11 14:38:52 -0500 | [diff] [blame] | 43 | * @brief Segmented & versioned data publisher. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 44 | * |
Davide Pesavento | 7c4246c | 2021-03-12 01:35:22 -0500 | [diff] [blame] | 45 | * Packetizes and publishes data from an input stream as `/prefix/<version>/<segment number>`. |
| 46 | * Unless another value is provided, the current time is used as the version number. |
| 47 | * The packet store always has at least one item, even when the input is empty. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 48 | */ |
| 49 | class Producer : noncopyable |
| 50 | { |
| 51 | public: |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 52 | struct Options |
| 53 | { |
| 54 | security::SigningInfo signingInfo; |
Davide Pesavento | 7c4246c | 2021-03-12 01:35:22 -0500 | [diff] [blame] | 55 | time::milliseconds freshnessPeriod = 10_s; |
| 56 | size_t maxSegmentSize = 8000; |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 57 | bool isQuiet = false; |
| 58 | bool isVerbose = false; |
| 59 | bool wantShowVersion = false; |
| 60 | }; |
| 61 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 62 | /** |
Davide Pesavento | b61e3e2 | 2022-11-11 14:38:52 -0500 | [diff] [blame] | 63 | * @brief Create the producer. |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 64 | * @param prefix prefix used to publish data; if the last component is not a valid |
| 65 | * version number, the current system time is used as version number. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 66 | */ |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 67 | Producer(const Name& prefix, Face& face, KeyChain& keyChain, std::istream& is, |
| 68 | const Options& opts); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 69 | |
| 70 | /** |
Davide Pesavento | b61e3e2 | 2022-11-11 14:38:52 -0500 | [diff] [blame] | 71 | * @brief Run the producer. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 72 | */ |
| 73 | void |
| 74 | run(); |
| 75 | |
| 76 | private: |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 77 | /** |
Davide Pesavento | b61e3e2 | 2022-11-11 14:38:52 -0500 | [diff] [blame] | 78 | * @brief Respond with a metadata packet containing the versioned content name. |
Chavoosh Ghasemi | 79991a0 | 2019-01-28 21:22:31 -0800 | [diff] [blame] | 79 | */ |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 80 | void |
Chavoosh Ghasemi | 79991a0 | 2019-01-28 21:22:31 -0800 | [diff] [blame] | 81 | processDiscoveryInterest(const Interest& interest); |
| 82 | |
| 83 | /** |
Davide Pesavento | b61e3e2 | 2022-11-11 14:38:52 -0500 | [diff] [blame] | 84 | * @brief Respond with the requested segment of content. |
Chavoosh Ghasemi | 79991a0 | 2019-01-28 21:22:31 -0800 | [diff] [blame] | 85 | */ |
| 86 | void |
| 87 | processSegmentInterest(const Interest& interest); |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 88 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 89 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 90 | std::vector<std::shared_ptr<Data>> m_store; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 91 | |
| 92 | private: |
| 93 | Name m_prefix; |
| 94 | Name m_versionedPrefix; |
| 95 | Face& m_face; |
| 96 | KeyChain& m_keyChain; |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 97 | const Options m_options; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 100 | } // namespace ndn::chunks |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 101 | |
| 102 | #endif // NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP |