22 #include <ndn-cxx/name-component.hpp> 28 , m_scheduler(m_face.getIoService())
29 , m_keyChain(keyChain)
36 const ndn::Block& block, ndn::time::milliseconds freshness,
37 const ndn::security::SigningInfo& signingInfo)
39 auto buf = std::make_shared<const ndn::Buffer>(block.wire(), block.size());
40 publish(interestName, dataName, buf, freshness, signingInfo);
45 const ndn::ConstBufferPtr& buffer,
46 ndn::time::milliseconds freshness,
47 const ndn::security::SigningInfo& signingInfo)
49 uint64_t interestSegment = 0;
50 if (interestName[-1].isSegment()) {
51 interestSegment = interestName[-1].toSegment();
54 const uint8_t* rawBuffer = buffer->data();
55 const uint8_t* segmentBegin = rawBuffer;
56 const uint8_t* end = rawBuffer + buffer->size();
58 size_t maxPacketSize = (ndn::MAX_NDN_PACKET_SIZE >> 1);
60 uint64_t totalSegments = buffer->size() / maxPacketSize;
62 ndn::Name segmentPrefix(dataName);
63 segmentPrefix.appendVersion();
65 uint64_t segmentNo = 0;
67 const uint8_t* segmentEnd = segmentBegin + maxPacketSize;
68 if (segmentEnd > end) {
72 ndn::Name segmentName(segmentPrefix);
73 segmentName.appendSegment(segmentNo);
76 auto data = std::make_shared<ndn::Data>(segmentName);
77 data->setContent(segmentBegin, segmentEnd - segmentBegin);
78 data->setFreshnessPeriod(freshness);
79 data->setFinalBlock(ndn::name::Component::fromSegment(totalSegments));
81 segmentBegin = segmentEnd;
83 m_keyChain.sign(*data, signingInfo);
87 if (interestSegment == segmentNo) {
91 m_ims.insert(*data, freshness);
92 m_scheduler.schedule(freshness, [
this, segmentName] { m_ims.erase(segmentName); });
95 }
while (segmentBegin < end);
101 auto it = m_ims.find(interestName);
SegmentPublisher(ndn::Face &face, ndn::KeyChain &keyChain, size_t imsLimit=100)
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::SigningInfo())
Put all the segments in memory.
bool replyFromStore(const ndn::Name &interestName)
Try to reply from memory, return false if we cannot find the segment.