blob: a3cd3938a42f9a48a95b56d27a81e87970517b52 [file] [log] [blame]
Eric Newberry2f041d22018-06-03 18:02:31 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventob3570c62022-02-19 19:19:00 -05003 * Copyright (c) 2014-2022, Regents of the University of California,
Eric Newberry2f041d22018-06-03 18:02:31 -07004 * 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 Pesavento6a1396e2019-07-26 15:03:28 -040026 * @author Davide Pesavento <davidepesa@gmail.com>
Eric Newberry2f041d22018-06-03 18:02:31 -070027 */
28
29#ifndef NDN_TOOLS_NDNPOKE_NDNPOKE_HPP
30#define NDN_TOOLS_NDNPOKE_NDNPOKE_HPP
31
32#include "core/common.hpp"
33
Davide Pesaventoe75861e2019-07-24 21:55:39 -040034#include <ndn-cxx/util/scheduler.hpp>
35
Davide Pesaventob3570c62022-02-19 19:19:00 -050036namespace ndn::peek {
Eric Newberry2f041d22018-06-03 18:02:31 -070037
38/**
39 * \brief options for NdnPoke
40 */
41struct PokeOptions
42{
Davide Pesaventoe75861e2019-07-24 21:55:39 -040043 // Data construction options
44 Name name;
Davide Pesavento6a1396e2019-07-26 15:03:28 -040045 time::milliseconds freshnessPeriod = DEFAULT_FRESHNESS_PERIOD;
Davide Pesaventoe75861e2019-07-24 21:55:39 -040046 bool wantFinalBlockId = false;
Eric Newberry2f041d22018-06-03 18:02:31 -070047 security::SigningInfo signingInfo;
Davide Pesaventoe75861e2019-07-24 21:55:39 -040048
49 // program behavior options
Davide Pesaventob3ae6342019-07-25 21:07:16 -040050 bool isVerbose = false;
Davide Pesavento6a1396e2019-07-26 15:03:28 -040051 bool wantUnsolicited = false;
Davide Pesavento242d5062022-03-11 16:34:23 -050052 std::optional<time::milliseconds> timeout;
Eric Newberry2f041d22018-06-03 18:02:31 -070053};
54
Davide Pesaventob3570c62022-02-19 19:19:00 -050055class NdnPoke : noncopyable
Eric Newberry2f041d22018-06-03 18:02:31 -070056{
57public:
Davide Pesaventoe75861e2019-07-24 21:55:39 -040058 NdnPoke(Face& face, KeyChain& keyChain, std::istream& input, const PokeOptions& options);
Eric Newberry2f041d22018-06-03 18:02:31 -070059
Davide Pesavento87434be2019-07-25 19:04:23 -040060 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 Newberry2f041d22018-06-03 18:02:31 -070078 void
79 start();
80
Eric Newberry2f041d22018-06-03 18:02:31 -070081private:
82 shared_ptr<Data>
Davide Pesaventoe75861e2019-07-24 21:55:39 -040083 createData() const;
Eric Newberry2f041d22018-06-03 18:02:31 -070084
Davide Pesaventob3ae6342019-07-25 21:07:16 -040085 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 Pesaventob3570c62022-02-19 19:19:00 -050095 onRegFailure(std::string_view reason);
Davide Pesaventob3ae6342019-07-25 21:07:16 -040096
Eric Newberry2f041d22018-06-03 18:02:31 -070097private:
Davide Pesaventoe75861e2019-07-24 21:55:39 -040098 const PokeOptions m_options;
Eric Newberry2f041d22018-06-03 18:02:31 -070099 Face& m_face;
100 KeyChain& m_keyChain;
Davide Pesaventoe75861e2019-07-24 21:55:39 -0400101 std::istream& m_input;
102 Scheduler m_scheduler;
103 ScopedRegisteredPrefixHandle m_registeredPrefix;
104 scheduler::ScopedEventId m_timeoutEvent;
Davide Pesavento87434be2019-07-25 19:04:23 -0400105 Result m_result = Result::UNKNOWN;
Eric Newberry2f041d22018-06-03 18:02:31 -0700106};
107
Davide Pesaventob3570c62022-02-19 19:19:00 -0500108} // namespace ndn::peek
Eric Newberry2f041d22018-06-03 18:02:31 -0700109
110#endif // NDN_TOOLS_NDNPOKE_NDNPOKE_HPP