Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | b54aabd | 2018-04-16 19:36:24 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -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> |
| 26 | * @author Zhuo Li <zhuoli@email.arizona.edu> |
| 27 | */ |
| 28 | |
| 29 | #ifndef NDN_TOOLS_NDNPEEK_NDNPEEK_HPP |
| 30 | #define NDN_TOOLS_NDNPEEK_NDNPEEK_HPP |
| 31 | |
| 32 | #include "core/common.hpp" |
Junxiao Shi | a5b60cc | 2017-07-26 01:35:48 +0000 | [diff] [blame] | 33 | #include <ndn-cxx/link.hpp> |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 34 | |
| 35 | namespace ndn { |
| 36 | namespace peek { |
| 37 | |
| 38 | /** |
| 39 | * @brief options for NdnPeek |
| 40 | */ |
| 41 | struct PeekOptions |
| 42 | { |
Junxiao Shi | b54aabd | 2018-04-16 19:36:24 +0000 | [diff] [blame] | 43 | // Interest construction options |
| 44 | std::string name; |
| 45 | bool canBePrefix = false; |
| 46 | bool mustBeFresh = false; |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 47 | shared_ptr<Link> link; |
Junxiao Shi | b54aabd | 2018-04-16 19:36:24 +0000 | [diff] [blame] | 48 | time::milliseconds interestLifetime = -1_ms; |
| 49 | |
| 50 | // output behavior options |
| 51 | bool isVerbose = false; |
| 52 | time::milliseconds timeout = -1_ms; |
| 53 | bool wantPayloadOnly = false; |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | enum class ResultCode { |
| 57 | NONE = -1, |
| 58 | DATA = 0, |
| 59 | NACK = 4, |
| 60 | TIMEOUT = 3 |
| 61 | }; |
| 62 | |
| 63 | class NdnPeek : boost::noncopyable |
| 64 | { |
| 65 | public: |
| 66 | NdnPeek(Face& face, const PeekOptions& options); |
| 67 | |
| 68 | /** |
| 69 | * @return the timeout |
| 70 | */ |
| 71 | time::milliseconds |
| 72 | getTimeout() const; |
| 73 | |
| 74 | /** |
| 75 | * @return the result of Peek execution |
| 76 | */ |
| 77 | ResultCode |
| 78 | getResultCode() const; |
| 79 | |
| 80 | /** |
| 81 | * @brief express the Interest |
| 82 | * @note The caller must invoke face.processEvents() afterwards |
| 83 | */ |
| 84 | void |
| 85 | start(); |
| 86 | |
| 87 | private: |
| 88 | Interest |
| 89 | createInterest() const; |
| 90 | |
| 91 | /** |
| 92 | * @brief called when a Data packet is received |
| 93 | */ |
| 94 | void |
| 95 | onData(const Data& data); |
| 96 | |
| 97 | /** |
| 98 | * @brief called when a Nack packet is received |
| 99 | */ |
| 100 | void |
| 101 | onNack(const lp::Nack& nack); |
| 102 | |
| 103 | private: |
| 104 | Face& m_face; |
| 105 | const PeekOptions& m_options; |
| 106 | time::steady_clock::TimePoint m_expressInterestTime; |
| 107 | time::milliseconds m_timeout; |
| 108 | ResultCode m_resultCode; |
| 109 | }; |
| 110 | |
| 111 | } // namespace peek |
| 112 | } // namespace ndn |
| 113 | |
| 114 | #endif // NDN_TOOLS_NDNPEEK_NDNPEEK_HPP |