blob: 5ffd8cf0ce1fe320f1de9cea9e87007d1586fc6b [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>
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
Eric Newberry2f041d22018-06-03 18:02:31 -070036namespace ndn {
37namespace peek {
38
39/**
40 * \brief options for NdnPoke
41 */
42struct PokeOptions
43{
Davide Pesaventoe75861e2019-07-24 21:55:39 -040044 // Data construction options
45 Name name;
Davide Pesavento6a1396e2019-07-26 15:03:28 -040046 time::milliseconds freshnessPeriod = DEFAULT_FRESHNESS_PERIOD;
Davide Pesaventoe75861e2019-07-24 21:55:39 -040047 bool wantFinalBlockId = false;
Eric Newberry2f041d22018-06-03 18:02:31 -070048 security::SigningInfo signingInfo;
Davide Pesaventoe75861e2019-07-24 21:55:39 -040049
50 // program behavior options
Davide Pesaventob3ae6342019-07-25 21:07:16 -040051 bool isVerbose = false;
Davide Pesavento6a1396e2019-07-26 15:03:28 -040052 bool wantUnsolicited = false;
Davide Pesaventode01c812019-07-24 23:46:09 -040053 optional<time::milliseconds> timeout;
Eric Newberry2f041d22018-06-03 18:02:31 -070054};
55
56class NdnPoke : boost::noncopyable
57{
58public:
Davide Pesaventoe75861e2019-07-24 21:55:39 -040059 NdnPoke(Face& face, KeyChain& keyChain, std::istream& input, const PokeOptions& options);
Eric Newberry2f041d22018-06-03 18:02:31 -070060
Davide Pesavento87434be2019-07-25 19:04:23 -040061 enum class Result {
62 DATA_SENT = 0,
63 UNKNOWN = 1,
64 // 2 is reserved for "malformed command line"
65 TIMEOUT = 3,
66 // 4 is reserved for "nack"
67 PREFIX_REG_FAIL = 5,
68 };
69
70 /**
71 * @return the result of NdnPoke execution
72 */
73 Result
74 getResult() const
75 {
76 return m_result;
77 }
78
Eric Newberry2f041d22018-06-03 18:02:31 -070079 void
80 start();
81
Eric Newberry2f041d22018-06-03 18:02:31 -070082private:
83 shared_ptr<Data>
Davide Pesaventoe75861e2019-07-24 21:55:39 -040084 createData() const;
Eric Newberry2f041d22018-06-03 18:02:31 -070085
Davide Pesaventob3ae6342019-07-25 21:07:16 -040086 void
87 sendData(const Data& data);
88
89 void
90 onInterest(const Interest& interest, const Data& data);
91
92 void
93 onRegSuccess();
94
95 void
96 onRegFailure(const std::string& reason);
97
Eric Newberry2f041d22018-06-03 18:02:31 -070098private:
Davide Pesaventoe75861e2019-07-24 21:55:39 -040099 const PokeOptions m_options;
Eric Newberry2f041d22018-06-03 18:02:31 -0700100 Face& m_face;
101 KeyChain& m_keyChain;
Davide Pesaventoe75861e2019-07-24 21:55:39 -0400102 std::istream& m_input;
103 Scheduler m_scheduler;
104 ScopedRegisteredPrefixHandle m_registeredPrefix;
105 scheduler::ScopedEventId m_timeoutEvent;
Davide Pesavento87434be2019-07-25 19:04:23 -0400106 Result m_result = Result::UNKNOWN;
Eric Newberry2f041d22018-06-03 18:02:31 -0700107};
108
109} // namespace peek
110} // namespace ndn
111
112#endif // NDN_TOOLS_NDNPOKE_NDNPOKE_HPP