22 #ifndef NDN_CXX_IMPL_FACE_IMPL_HPP 23 #define NDN_CXX_IMPL_FACE_IMPL_HPP 60 class Face::Impl :
public std::enable_shared_from_this<Face::Impl>
66 , m_nfdController(m_face, keyChain)
68 auto onEmptyPitOrNoRegisteredPrefixes = [
this] {
74 if (m_pendingInterestTable.
empty() && m_registeredPrefixTable.
empty()) {
75 m_face.m_transport->pause();
76 m_processEventsTimeoutEvent.
cancel();
81 m_pendingInterestTable.
onEmpty.connect(onEmptyPitOrNoRegisteredPrefixes);
82 m_registeredPrefixTable.
onEmpty.connect(onEmptyPitOrNoRegisteredPrefixes);
95 const Interest& interest2 = *interest;
96 auto& entry = m_pendingInterestTable.
put(
id,
std::move(interest), afterSatisfied,
97 afterNacked, afterTimeout, m_scheduler);
100 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest2);
101 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest2);
103 entry.recordForwarding();
106 dispatchInterest(entry, interest2);
113 auto impl = w.lock();
114 if (impl !=
nullptr) {
115 impl->m_pendingInterestTable.erase(
id);
123 m_pendingInterestTable.
clear();
131 bool hasAppMatch =
false, hasForwarderMatch =
false;
143 hasForwarderMatch =
true;
150 return hasForwarderMatch || !hasAppMatch;
158 optional<lp::Nack> outNack;
165 optional<lp::Nack> outNack1 = entry.
recordNack(nack);
190 m_interestFilterTable.
put(
id, filter, onInterest);
197 auto impl = w.lock();
198 if (impl !=
nullptr) {
199 impl->unsetInterestFilter(
id);
207 const Interest& interest2 = *interest;
208 auto& entry = m_pendingInterestTable.
insert(
std::move(interest), m_scheduler);
209 dispatchInterest(entry, interest2);
217 if (!shouldSendToForwarder) {
224 addFieldFromTag<lp::CachePolicyField, lp::CachePolicyTag>(lpPacket, data);
225 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
244 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, *outNack);
246 const Interest& interest = outNack->getInterest();
247 m_face.m_transport->send(finishEncoding(
std::move(lpPacket), interest.wireEncode(),
248 'N', interest.getName()));
260 auto id = m_registeredPrefixTable.
allocateId();
270 auto& filterRecord = m_interestFilterTable.
insert(*filter, onInterest);
271 filterId = filterRecord.
getId();
273 m_registeredPrefixTable.
put(
id, prefix, options, filterId);
281 onFailure(prefix, resp.getText());
294 auto impl = w.lock();
295 if (impl !=
nullptr) {
296 impl->unregisterPrefix(
id, onSuccess, onFailure);
305 if (!m_face.m_transport->isConnected()) {
306 m_face.m_transport->connect([
this] (
const Block& wire) { m_face.onReceiveElement(wire); });
309 if (wantResume && !m_face.m_transport->isReceiving()) {
310 m_face.m_transport->resume();
317 m_pendingInterestTable.
clear();
318 m_registeredPrefixTable.
clear();
333 if (!lpPacket.empty()) {
335 wire = lpPacket.wireEncode();
361 const auto* record = m_interestFilterTable.
get(
id);
362 if (record !=
nullptr) {
363 NDN_LOG_INFO(
"unsetting InterestFilter: " << record->getFilter());
364 m_interestFilterTable.
erase(
id);
373 const auto* record = m_registeredPrefixTable.
get(
id);
374 if (record ==
nullptr) {
376 onFailure(
"Unrecognized RegisteredPrefixHandle");
381 if (record->getFilterId() != 0) {
382 unsetInterestFilter(record->getFilterId());
385 NDN_LOG_INFO(
"unregistering prefix: " << record->getPrefix());
390 NDN_LOG_INFO(
"unregistered prefix: " << record->getPrefix());
391 m_registeredPrefixTable.
erase(
id);
397 NDN_LOG_INFO(
"unregister prefix failed: " << record->getPrefix());
399 onFailure(resp.getText());
402 record->getCommandOptions());
420 #endif // NDN_CXX_IMPL_FACE_IMPL_HPP boost::chrono::seconds seconds
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
void invokeInterestCallback(const Interest &interest) const
invokes the InterestCallback
Copyright (c) 2011-2015 Regents of the University of California.
void removeAllPendingInterests()
void forEach(const Visitor &f)
Visit all records.
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregistering a prefix fails.
shared_ptr< const Interest > getInterest() const
represents parameters in a ControlCommand request or response
implementation detail of Face
Record & insert(TArgs &&... args)
Insert a record with newly assigned ID.
NDN_CXX_NODISCARD bool empty() const noexcept
void removeIf(const Visitor &f)
Visit all records with the option to erase.
util::Signal< RecordContainer< T > > onEmpty
Signals when container becomes empty.
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
void asyncUnregisterPrefix(detail::RecordId id, const UnregisterPrefixSuccessCallback &onSuccess, const UnregisterPrefixFailureCallback &onFailure)
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
const InterestFilter & getFilter() const
DummyIoService & getIoService()
#define NDN_LOG_DEBUG(expression)
bool matchesInterest(const Interest &other) const
Check if this Interest matches other.
optional< lp::Nack > recordNack(const lp::Nack &nack)
Record an incoming Nack against a forwarded Interest.
Associates an InterestFilter with an Interest callback.
const_iterator begin() const
Get begin iterator of encoded wire.
void asyncRemovePendingInterest(detail::RecordId id)
bool doesMatch(const PendingInterest &entry) const
Check if Interest name matches the filter.
Represents a TLV element of the NDN packet format.
Represents an Interest packet.
const NackHeader & getHeader() const
void putNack(const lp::Nack &nack)
EventId schedule(time::nanoseconds after, EventCallback callback)
Schedule a one-time event after the specified delay.
Record * get(RecordId id)
Retrieve record by ID.
void processIncomingInterest(shared_ptr< const Interest > interest)
represents a Network Nack
void invokeNackCallback(const lp::Nack &nack)
Invoke the Nack callback.
void recordForwarding()
Record that the Interest has been forwarded to one destination.
size_t size() const
Return the size of the encoded wire, i.e., of the whole TLV.
contains options for ControlCommand execution
Record & put(RecordId id, TArgs &&... args)
Insert a record with given ID.
detail::RecordId registerPrefix(const Name &prefix, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, uint64_t flags, const nfd::CommandOptions &options, const optional< InterestFilter > &filter, const InterestCallback &onInterest)
Provide a communication channel with local or remote NDN forwarder.
NFD Management protocol client.
#define NDN_LOG_INFO(expression)
void ensureConnected(bool wantResume)
const Name & getName() const noexcept
Get name.
function< void(const Name &, const std::string &)> RegisterPrefixFailureCallback
Callback invoked when registerPrefix or setInterestFilter command fails.
function< void(const Name &)> RegisterPrefixSuccessCallback
Callback invoked when registerPrefix or setInterestFilter command succeeds.
Represents an absolute name.
void putData(const Data &data)
represents a rib/unregister command
Generic time-based scheduler.
represents a rib/register command
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when an incoming Interest matches the specified InterestFilter.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend wire encoding to encoder.
void setInterestFilter(detail::RecordId id, const InterestFilter &filter, const InterestCallback &onInterest)
bool satisfyPendingInterests(const Data &data)
Impl(Face &face, KeyChain &keyChain)
void expressInterest(detail::RecordId id, shared_ptr< const Interest > interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
const Name & getName() const noexcept
void asyncUnsetInterestFilter(detail::RecordId id)
void cancel()
Cancel the operation.
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Prepend wire encoding to encoder.
optional< lp::Nack > nackPendingInterests(const lp::Nack &nack)
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregistering a prefix succeeds.
#define NDN_LOG_INIT(name)
declare a log module
Interest was received from this app via Face::expressInterest API.
function< void(const Interest &)> TimeoutCallback
Callback invoked when an expressed Interest times out.
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when a Nack is received in response to an expressed Interest.
PendingInterestOrigin getOrigin() const
Represents a Data packet.
Stores a pending Interest and associated callbacks.
const_iterator end() const
Get end iterator of encoded wire.
const Interest & getInterest() const
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when an expressed Interest is satisfied by a Data packet.
Exception thrown when attempting to send a packet over size limit.
const size_t MAX_NDN_PACKET_SIZE
Practical size limit of a network-layer packet.
void invokeDataCallback(const Data &data)
Invoke the Data callback.