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