NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
notification-stream.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018 Regents of the University of California,
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-cxx library (NDN C++ library with eXperimental eXtensions).
12  *
13  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU Lesser General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any later version.
16  *
17  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20  *
21  * You should have received copies of the GNU General Public License and GNU Lesser
22  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
26  */
27 
28 #ifndef NDN_UTIL_NOTIFICATION_STREAM_HPP
29 #define NDN_UTIL_NOTIFICATION_STREAM_HPP
30 
31 #include "ndn-cxx/face.hpp"
32 #include "ndn-cxx/name.hpp"
35 
36 namespace ndn {
37 namespace util {
38 
42 template<typename Notification>
43 class NotificationStream : noncopyable
44 {
45 public:
46  BOOST_CONCEPT_ASSERT((WireEncodable<Notification>));
47 
48  NotificationStream(Face& face, const Name& prefix, KeyChain& keyChain)
49  : m_face(face)
50  , m_prefix(prefix)
51  , m_keyChain(keyChain)
52  , m_sequenceNo(0)
53  {
54  }
55 
56  virtual
57  ~NotificationStream() = default;
58 
59  void
60  postNotification(const Notification& notification)
61  {
62  Name dataName = m_prefix;
63  dataName.appendSequenceNumber(m_sequenceNo);
64 
65  shared_ptr<Data> data = make_shared<Data>(dataName);
66  data->setContent(notification.wireEncode());
67  data->setFreshnessPeriod(1_s);
68 
69  m_keyChain.sign(*data);
70  m_face.put(*data);
71 
72  ++m_sequenceNo;
73  }
74 
75 private:
76  Face& m_face;
77  const Name m_prefix;
78  KeyChain& m_keyChain;
79  uint64_t m_sequenceNo;
80 };
81 
82 } // namespace util
83 } // namespace ndn
84 
85 #endif // NDN_UTIL_NOTIFICATION_STREAM_HPP
Copyright (c) 2011-2015 Regents of the University of California.
The interface of signing key management.
Definition: key-chain.hpp:46
provides a publisher of Notification Stream
void postNotification(const Notification &notification)
virtual ~NotificationStream()=default
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:93
NotificationStream(Face &face, const Name &prefix, KeyChain &keyChain)
Name & appendSequenceNumber(uint64_t seqNo)
Append a sequence number component.
Definition: name.hpp:399
Represents an absolute name.
Definition: name.hpp:43
void sign(Data &data, const SigningInfo &params=getDefaultSigningInfo())
Sign data according to the supplied signing information.
Definition: key-chain.cpp:430
void put(Data data)
Publish data packet.
Definition: face.cpp:169
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:44