22 #include <ndn-cxx/name-component.hpp> 29 , m_scheduler(m_face.getIoService())
30 , m_keyChain(keyChain)
37 const ndn::Block& block, ndn::time::milliseconds freshness,
38 const ndn::security::SigningInfo& signingInfo)
40 uint64_t interestSegment = 0;
41 if (interestName[-1].isSegment()) {
42 interestSegment = interestName[-1].toSegment();
45 ndn::EncodingBuffer buffer;
46 buffer.prependBlock(std::move(block));
48 const uint8_t* rawBuffer = buffer.buf();
49 const uint8_t* segmentBegin = rawBuffer;
50 const uint8_t* end = rawBuffer + buffer.size();
52 size_t maxPacketSize = (ndn::MAX_NDN_PACKET_SIZE >> 1);
54 uint64_t totalSegments = buffer.size() / maxPacketSize;
56 ndn::Name segmentPrefix(dataName);
57 segmentPrefix.appendVersion();
59 uint64_t segmentNo = 0;
61 const uint8_t* segmentEnd = segmentBegin + maxPacketSize;
62 if (segmentEnd > end) {
66 ndn::Name segmentName(segmentPrefix);
67 segmentName.appendSegment(segmentNo);
70 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(segmentName);
71 data->setContent(segmentBegin, segmentEnd - segmentBegin);
72 data->setFreshnessPeriod(freshness);
73 data->setFinalBlock(ndn::name::Component::fromSegment(totalSegments));
75 segmentBegin = segmentEnd;
77 m_keyChain.sign(*data, signingInfo);
81 if (interestSegment == segmentNo) {
85 m_ims.insert(*data, freshness);
86 m_scheduler.scheduleEvent(freshness,
88 m_ims.erase(segmentName);
92 }
while (segmentBegin < end);
98 auto it = m_ims.find(interestName);
void publish(const ndn::Name &interestName, const ndn::Name &dataName, const ndn::Block &block, ndn::time::milliseconds freshness, const ndn::security::SigningInfo &signingInfo=ndn::security::v2::KeyChain::getDefaultSigningInfo())
Put all the segments in memory.
SegmentPublisher(ndn::Face &face, ndn::KeyChain &keyChain, size_t imsLimit=MAX_SEGMENTS_STORED)
bool replyFromStore(const ndn::Name &interestName)
Try to reply from memory, return false if we cannot find the segment.