blob: e47da81cf3bc4a4afaa443b3c3b4a83768556fa1 [file] [log] [blame]
Eric Newberry2f041d22018-06-03 18:02:31 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Junxiao Shi06d008c2019-02-04 08:26:59 +00003 * Copyright (c) 2014-2019, 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>
26 */
27
28#ifndef NDN_TOOLS_NDNPOKE_NDNPOKE_HPP
29#define NDN_TOOLS_NDNPOKE_NDNPOKE_HPP
30
31#include "core/common.hpp"
32
Davide Pesaventoe75861e2019-07-24 21:55:39 -040033#include <ndn-cxx/util/scheduler.hpp>
34
Eric Newberry2f041d22018-06-03 18:02:31 -070035namespace ndn {
36namespace peek {
37
38/**
39 * \brief options for NdnPoke
40 */
41struct PokeOptions
42{
Davide Pesaventoe75861e2019-07-24 21:55:39 -040043 // Data construction options
44 Name name;
45 optional<time::milliseconds> freshnessPeriod;
46 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
50 bool wantForceData = false;
51 time::milliseconds timeout = 10_s;
Eric Newberry2f041d22018-06-03 18:02:31 -070052};
53
54class NdnPoke : boost::noncopyable
55{
56public:
Davide Pesaventoe75861e2019-07-24 21:55:39 -040057 NdnPoke(Face& face, KeyChain& keyChain, std::istream& input, const PokeOptions& options);
Eric Newberry2f041d22018-06-03 18:02:31 -070058
Davide Pesavento87434be2019-07-25 19:04:23 -040059 enum class Result {
60 DATA_SENT = 0,
61 UNKNOWN = 1,
62 // 2 is reserved for "malformed command line"
63 TIMEOUT = 3,
64 // 4 is reserved for "nack"
65 PREFIX_REG_FAIL = 5,
66 };
67
68 /**
69 * @return the result of NdnPoke execution
70 */
71 Result
72 getResult() const
73 {
74 return m_result;
75 }
76
Eric Newberry2f041d22018-06-03 18:02:31 -070077 void
78 start();
79
Eric Newberry2f041d22018-06-03 18:02:31 -070080private:
81 shared_ptr<Data>
Davide Pesaventoe75861e2019-07-24 21:55:39 -040082 createData() const;
Eric Newberry2f041d22018-06-03 18:02:31 -070083
84private:
Davide Pesaventoe75861e2019-07-24 21:55:39 -040085 const PokeOptions m_options;
Eric Newberry2f041d22018-06-03 18:02:31 -070086 Face& m_face;
87 KeyChain& m_keyChain;
Davide Pesaventoe75861e2019-07-24 21:55:39 -040088 std::istream& m_input;
89 Scheduler m_scheduler;
90 ScopedRegisteredPrefixHandle m_registeredPrefix;
91 scheduler::ScopedEventId m_timeoutEvent;
Davide Pesavento87434be2019-07-25 19:04:23 -040092 Result m_result = Result::UNKNOWN;
Eric Newberry2f041d22018-06-03 18:02:31 -070093};
94
95} // namespace peek
96} // namespace ndn
97
98#endif // NDN_TOOLS_NDNPOKE_NDNPOKE_HPP