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 | /* |
Chavoosh Ghasemi | 79991a0 | 2019-01-28 21:22:31 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2016-2019, 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 | |
| 35 | namespace ndn { |
| 36 | namespace chunks { |
| 37 | |
| 38 | /** |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 39 | * @brief Segmented & versioned data publisher |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 40 | * |
| 41 | * Packetizes and publishes data from an input stream under /prefix/<version>/<segment number>. |
| 42 | * The current time is used as the version number. The store has always at least one element (also |
| 43 | * with empty input stream). |
| 44 | */ |
| 45 | class Producer : noncopyable |
| 46 | { |
| 47 | public: |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 48 | struct Options |
| 49 | { |
| 50 | security::SigningInfo signingInfo; |
| 51 | time::milliseconds freshnessPeriod{10000}; |
| 52 | size_t maxSegmentSize = MAX_NDN_PACKET_SIZE >> 1; |
| 53 | bool isQuiet = false; |
| 54 | bool isVerbose = false; |
| 55 | bool wantShowVersion = false; |
| 56 | }; |
| 57 | |
| 58 | public: |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 59 | /** |
| 60 | * @brief Create the Producer |
| 61 | * |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 62 | * @param prefix prefix used to publish data; if the last component is not a valid |
| 63 | * version number, the current system time is used as version number. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 64 | */ |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 65 | Producer(const Name& prefix, Face& face, KeyChain& keyChain, std::istream& is, |
| 66 | const Options& opts); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * @brief Run the Producer |
| 70 | */ |
| 71 | void |
| 72 | run(); |
| 73 | |
| 74 | private: |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 75 | /** |
| 76 | * @brief Split the input stream in data packets and save them to the store |
| 77 | * |
| 78 | * Create data packets reading all the characters from the input stream until EOF, or an |
| 79 | * error occurs. Each data packet has a maximum payload size of m_maxSegmentSize value and is |
| 80 | * stored inside the vector m_store. An empty data packet is created and stored if the input |
| 81 | * stream is empty. |
| 82 | * |
| 83 | * @return Number of data packets contained in the store after the operation |
| 84 | */ |
| 85 | void |
| 86 | populateStore(std::istream& is); |
| 87 | |
Chavoosh Ghasemi | 79991a0 | 2019-01-28 21:22:31 -0800 | [diff] [blame^] | 88 | /** |
| 89 | * @brief Respond with a metadata packet containing the versioned content name |
| 90 | */ |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 91 | void |
Chavoosh Ghasemi | 79991a0 | 2019-01-28 21:22:31 -0800 | [diff] [blame^] | 92 | processDiscoveryInterest(const Interest& interest); |
| 93 | |
| 94 | /** |
| 95 | * @brief Respond with the requested segment of content |
| 96 | */ |
| 97 | void |
| 98 | processSegmentInterest(const Interest& interest); |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 99 | |
| 100 | void |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 101 | onRegisterFailed(const Name& prefix, const std::string& reason); |
| 102 | |
| 103 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 104 | std::vector<shared_ptr<Data>> m_store; |
| 105 | |
| 106 | private: |
| 107 | Name m_prefix; |
| 108 | Name m_versionedPrefix; |
| 109 | Face& m_face; |
| 110 | KeyChain& m_keyChain; |
Davide Pesavento | 6f76afc | 2017-09-19 18:43:51 -0400 | [diff] [blame] | 111 | const Options m_options; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace chunks |
| 115 | } // namespace ndn |
| 116 | |
| 117 | #endif // NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP |