26 #ifndef NLSR_PUBLISHER_SEGMENT_PUBLISHER_HPP 27 #define NLSR_PUBLISHER_SEGMENT_PUBLISHER_HPP 29 #include <ndn-cxx/encoding/encoding-buffer.hpp> 30 #include <ndn-cxx/security/key-chain.hpp> 37 template <
class FaceBase>
42 ndn::KeyChain& keyChain,
43 const ndn::security::SigningInfo& signingInfo,
46 , m_keyChain(keyChain)
47 , m_signingInfo(signingInfo)
48 , m_freshnessPeriod(freshnessPeriod)
62 static const size_t MAX_SEGMENT_SIZE = ndn::MAX_NDN_PACKET_SIZE >> 1;
63 return MAX_SEGMENT_SIZE;
66 static constexpr ndn::time::milliseconds
69 return ndn::time::milliseconds(1000);
82 ndn::EncodingBuffer buffer;
85 const uint8_t* rawBuffer = buffer.buf();
86 const uint8_t* segmentBegin = rawBuffer;
87 const uint8_t* end = rawBuffer + buffer.size();
89 ndn::Name segmentPrefix(prefix);
90 segmentPrefix.appendVersion();
92 uint64_t segmentNo = 0;
95 if (segmentEnd > end) {
99 ndn::Name segmentName(segmentPrefix);
100 segmentName.appendSegment(segmentNo);
102 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(segmentName);
103 data->setContent(segmentBegin, segmentEnd - segmentBegin);
104 data->setFreshnessPeriod(m_freshnessPeriod);
106 segmentBegin = segmentEnd;
107 if (segmentBegin >= end) {
108 data->setFinalBlockId(segmentName[-1]);
111 publishSegment(data);
113 }
while (segmentBegin < end);
120 generate(ndn::EncodingBuffer& outBuffer) = 0;
126 publishSegment(std::shared_ptr<ndn::Data>& data)
128 m_keyChain.sign(*data, m_signingInfo);
134 ndn::KeyChain& m_keyChain;
135 const ndn::security::SigningInfo& m_signingInfo;
136 const ndn::time::milliseconds m_freshnessPeriod;
141 #endif // NLSR_PUBLISHER_SEGMENT_PUBLISHER_HPP SegmentPublisher(FaceBase &face, ndn::KeyChain &keyChain, const ndn::security::SigningInfo &signingInfo, const ndn::time::milliseconds &freshnessPeriod=getDefaultFreshness())
virtual ~SegmentPublisher()
static size_t getMaxSegmentSize()
Define the max segment size as half the max NDN packet size.
virtual size_t generate(ndn::EncodingBuffer &outBuffer)=0
In a derived class, write the octets into outBuffer.
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
void publish(const ndn::Name &prefix)
Publish data under the provided prefix.
static constexpr ndn::time::milliseconds getDefaultFreshness()
provides a publisher of Status Dataset or other segmented octet stream