blob: 4eac8d36b5efe6c27cf35b6de1641fb463abb87c [file] [log] [blame]
Zhuo Lib3558892016-08-12 15:51:12 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shib54aabd2018-04-16 19:36:24 +00002/*
3 * Copyright (c) 2014-2018, 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{
Junxiao Shib54aabd2018-04-16 19:36:24 +000043 // Interest construction options
44 std::string name;
45 bool canBePrefix = false;
46 bool mustBeFresh = false;
Zhuo Lib3558892016-08-12 15:51:12 -070047 shared_ptr<Link> link;
Junxiao Shib54aabd2018-04-16 19:36:24 +000048 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 Lib3558892016-08-12 15:51:12 -070054};
55
56enum class ResultCode {
57 NONE = -1,
58 DATA = 0,
59 NACK = 4,
60 TIMEOUT = 3
61};
62
63class NdnPeek : boost::noncopyable
64{
65public:
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
87private:
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
103private:
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