NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
28 #ifndef NDN_UTIL_NOTIFICATION_STREAM_HPP
29 #define NDN_UTIL_NOTIFICATION_STREAM_HPP
30 
31 #include "../name.hpp"
32 #include "../face.hpp"
33 #include "../security/v2/key-chain.hpp"
34 
35 #include "concepts.hpp"
36 
37 namespace ndn {
38 namespace util {
39 
43 template<typename Notification>
44 class NotificationStream : noncopyable
45 {
46 public:
47  BOOST_CONCEPT_ASSERT((WireEncodable<Notification>));
48 
49  NotificationStream(Face& face, const Name& prefix, KeyChain& keyChain)
50  : m_face(face)
51  , m_prefix(prefix)
52  , m_keyChain(keyChain)
53  , m_sequenceNo(0)
54  {
55  }
56 
57  virtual
58  ~NotificationStream() = default;
59 
60  void
61  postNotification(const Notification& notification)
62  {
63  Name dataName = m_prefix;
64  dataName.appendSequenceNumber(m_sequenceNo);
65 
66  shared_ptr<Data> data = make_shared<Data>(dataName);
67  data->setContent(notification.wireEncode());
68  data->setFreshnessPeriod(time::seconds(1));
69 
70  m_keyChain.sign(*data);
71  m_face.put(*data);
72 
73  ++m_sequenceNo;
74  }
75 
76 private:
77  Face& m_face;
78  const Name m_prefix;
79  KeyChain& m_keyChain;
80  uint64_t m_sequenceNo;
81 };
82 
83 } // namespace util
84 } // namespace ndn
85 
86 #endif // NDN_UTIL_NOTIFICATION_STREAM_HPP
Copyright (c) 2011-2015 Regents of the University of California.
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:95
NotificationStream(Face &face, const Name &prefix, KeyChain &keyChain)
Name & appendSequenceNumber(uint64_t seqNo)
Append a sequence number component.
Definition: name.hpp:406
Represents an absolute name.
Definition: name.hpp:42
void put(Data data)
Publish data packet.
Definition: face.cpp:183
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:44
ndn security v2 KeyChain
Definition: key-chain.cpp:76