Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 13 | * |
| 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
Davide Pesavento | 6a1396e | 2019-07-26 15:03:28 -0400 | [diff] [blame] | 26 | * @author Davide Pesavento <davidepesa@gmail.com> |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #ifndef NDN_TOOLS_NDNPOKE_NDNPOKE_HPP |
| 30 | #define NDN_TOOLS_NDNPOKE_NDNPOKE_HPP |
| 31 | |
| 32 | #include "core/common.hpp" |
| 33 | |
Davide Pesavento | e75861e | 2019-07-24 21:55:39 -0400 | [diff] [blame] | 34 | #include <ndn-cxx/util/scheduler.hpp> |
| 35 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 36 | namespace ndn::peek { |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * \brief options for NdnPoke |
| 40 | */ |
| 41 | struct PokeOptions |
| 42 | { |
Davide Pesavento | e75861e | 2019-07-24 21:55:39 -0400 | [diff] [blame] | 43 | // Data construction options |
| 44 | Name name; |
Davide Pesavento | 6a1396e | 2019-07-26 15:03:28 -0400 | [diff] [blame] | 45 | time::milliseconds freshnessPeriod = DEFAULT_FRESHNESS_PERIOD; |
Davide Pesavento | e75861e | 2019-07-24 21:55:39 -0400 | [diff] [blame] | 46 | bool wantFinalBlockId = false; |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 47 | security::SigningInfo signingInfo; |
Davide Pesavento | e75861e | 2019-07-24 21:55:39 -0400 | [diff] [blame] | 48 | |
| 49 | // program behavior options |
Davide Pesavento | b3ae634 | 2019-07-25 21:07:16 -0400 | [diff] [blame] | 50 | bool isVerbose = false; |
Davide Pesavento | 6a1396e | 2019-07-26 15:03:28 -0400 | [diff] [blame] | 51 | bool wantUnsolicited = false; |
Davide Pesavento | 242d506 | 2022-03-11 16:34:23 -0500 | [diff] [blame^] | 52 | std::optional<time::milliseconds> timeout; |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 55 | class NdnPoke : noncopyable |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 56 | { |
| 57 | public: |
Davide Pesavento | e75861e | 2019-07-24 21:55:39 -0400 | [diff] [blame] | 58 | NdnPoke(Face& face, KeyChain& keyChain, std::istream& input, const PokeOptions& options); |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 59 | |
Davide Pesavento | 87434be | 2019-07-25 19:04:23 -0400 | [diff] [blame] | 60 | enum class Result { |
| 61 | DATA_SENT = 0, |
| 62 | UNKNOWN = 1, |
| 63 | // 2 is reserved for "malformed command line" |
| 64 | TIMEOUT = 3, |
| 65 | // 4 is reserved for "nack" |
| 66 | PREFIX_REG_FAIL = 5, |
| 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * @return the result of NdnPoke execution |
| 71 | */ |
| 72 | Result |
| 73 | getResult() const |
| 74 | { |
| 75 | return m_result; |
| 76 | } |
| 77 | |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 78 | void |
| 79 | start(); |
| 80 | |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 81 | private: |
| 82 | shared_ptr<Data> |
Davide Pesavento | e75861e | 2019-07-24 21:55:39 -0400 | [diff] [blame] | 83 | createData() const; |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 84 | |
Davide Pesavento | b3ae634 | 2019-07-25 21:07:16 -0400 | [diff] [blame] | 85 | void |
| 86 | sendData(const Data& data); |
| 87 | |
| 88 | void |
| 89 | onInterest(const Interest& interest, const Data& data); |
| 90 | |
| 91 | void |
| 92 | onRegSuccess(); |
| 93 | |
| 94 | void |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 95 | onRegFailure(std::string_view reason); |
Davide Pesavento | b3ae634 | 2019-07-25 21:07:16 -0400 | [diff] [blame] | 96 | |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 97 | private: |
Davide Pesavento | e75861e | 2019-07-24 21:55:39 -0400 | [diff] [blame] | 98 | const PokeOptions m_options; |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 99 | Face& m_face; |
| 100 | KeyChain& m_keyChain; |
Davide Pesavento | e75861e | 2019-07-24 21:55:39 -0400 | [diff] [blame] | 101 | std::istream& m_input; |
| 102 | Scheduler m_scheduler; |
| 103 | ScopedRegisteredPrefixHandle m_registeredPrefix; |
| 104 | scheduler::ScopedEventId m_timeoutEvent; |
Davide Pesavento | 87434be | 2019-07-25 19:04:23 -0400 | [diff] [blame] | 105 | Result m_result = Result::UNKNOWN; |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 108 | } // namespace ndn::peek |
Eric Newberry | 2f041d2 | 2018-06-03 18:02:31 -0700 | [diff] [blame] | 109 | |
| 110 | #endif // NDN_TOOLS_NDNPOKE_NDNPOKE_HPP |