43 BOOST_THROW_EXCEPTION(std::invalid_argument(
"prefix does not start with Interest Name"));
46 if (m_state != State::INITIAL) {
47 BOOST_THROW_EXCEPTION(std::domain_error(
"state is not in INITIAL"));
52 if (!m_prefix[-1].isVersion()) {
59 const time::milliseconds&
75 if (m_state == State::FINALIZED) {
76 BOOST_THROW_EXCEPTION(std::domain_error(
"state is in FINALIZED"));
79 m_state = State::RESPONDED;
81 size_t nBytesLeft = block.
size();
83 while (nBytesLeft > 0) {
84 size_t nBytesAppend = std::min(nBytesLeft,
86 m_buffer->appendByteArray(block.
wire() + (block.
size() - nBytesLeft), nBytesAppend);
87 nBytesLeft -= nBytesAppend;
91 m_dataSender(
Name(m_prefix).appendSegment(m_segmentNo++), content,
92 MetaInfo().setFreshnessPeriod(m_expiry));
94 m_buffer = std::make_shared<EncodingBuffer>();
102 if (m_state == State::FINALIZED) {
103 BOOST_THROW_EXCEPTION(std::domain_error(
"state is in FINALIZED"));
106 m_state = State::FINALIZED;
108 auto dataName =
Name(m_prefix).appendSegment(m_segmentNo++);
110 MetaInfo().setFreshnessPeriod(m_expiry).setFinalBlockId(dataName[-1]));
116 if (m_state != State::INITIAL) {
117 BOOST_THROW_EXCEPTION(std::domain_error(
"state is in REPONSED or FINALIZED"));
120 m_state = State::FINALIZED;
128 : m_interest(interest)
129 , m_dataSender(dataSender)
130 , m_expiry(DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD)
133 , m_state(State::INITIAL)
const Name & getPrefix() const
StatusDatasetContext(const Interest &interest, const DataSender &dataSender)
void reject(const ControlResponse &resp=ControlResponse().setCode(400))
declare the non-existence of a response
const Name & getName() const
Copyright (c) 2011-2015 Regents of the University of California.
StatusDatasetContext & setExpiry(const time::milliseconds &expiry)
set expiration duration
indicates a producer generated NACK
const time::milliseconds DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD
Class representing a wire element of NDN-TLV packet format.
represents an Interest packet
const Block & wireEncode() const
EncodingImpl< EncoderTag > EncodingBuffer
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const Block const MetaInfo &metaInfo DataSender
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const Block & content
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block type type with value from a buffer value of size length.
void end()
end the response successfully after appending zero or more blocks
Name abstraction to represent an absolute name.
const uint8_t * wire() const
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
StatusDatasetContext & setPrefix(const Name &prefix)
change prefix of Data packets
void append(const Block &block)
append a Block to the response
const time::milliseconds & getExpiry() const
Name & appendVersion(uint64_t version)
Append version using NDN naming conventions.
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size