24 #include "ndn-cxx/impl/face-impl.hpp"    34 #define IO_CAPTURE_WEAK_IMPL(OP) \    36     weak_ptr<Impl> implWeak(m_impl); \    37     m_ioService.OP([=] { \    38       auto impl = implWeak.lock(); \    39       if (impl != nullptr) {    40 #define IO_CAPTURE_WEAK_IMPL_END \    48   : 
Error((pktType == 
'I' ? 
"Interest " : pktType == 
'D' ? 
"Data " : 
"Nack ") +
    49           name.toUri() + 
" encodes into " + 
to_string(wireSize) + 
" octets, "    58   : m_internalIoService(make_unique<
boost::asio::io_service>())
    59   , m_ioService(*m_internalIoService)
    60   , m_internalKeyChain(make_unique<
KeyChain>())
    62   construct(
std::move(transport), *m_internalKeyChain);
    66   : m_ioService(ioService)
    67   , m_internalKeyChain(make_unique<
KeyChain>())
    69   construct(
nullptr, *m_internalKeyChain);
    72 Face::Face(
const std::string& host, 
const std::string& port)
    73   : m_internalIoService(make_unique<
boost::asio::io_service>())
    74   , m_ioService(*m_internalIoService)
    75   , m_internalKeyChain(make_unique<
KeyChain>())
    77   construct(make_shared<TcpTransport>(host, port), *m_internalKeyChain);
    81   : m_internalIoService(make_unique<
boost::asio::io_service>())
    82   , m_ioService(*m_internalIoService)
    84   construct(
std::move(transport), keyChain);
    87 Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService)
    88   : m_ioService(ioService)
    89   , m_internalKeyChain(make_unique<
KeyChain>())
    91   construct(
std::move(transport), *m_internalKeyChain);
    94 Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, 
KeyChain& keyChain)
    95   : m_ioService(ioService)
    97   construct(
std::move(transport), keyChain);
   100 shared_ptr<Transport>
   101 Face::makeDefaultTransport()
   106   std::string transportUri;
   108   const char* transportEnviron = getenv(
"NDN_CLIENT_TRANSPORT");
   109   if (transportEnviron != 
nullptr) {
   110     transportUri = transportEnviron;
   117   if (transportUri.empty()) {
   122   std::string protocol;
   127     if (protocol == 
"unix") {
   130     else if (protocol == 
"tcp" || protocol == 
"tcp4" || protocol == 
"tcp6") {
   146 Face::construct(shared_ptr<Transport> transport, 
KeyChain& keyChain)
   148   BOOST_ASSERT(m_impl == 
nullptr);
   149   m_impl = make_shared<Impl>(*
this, keyChain);
   151   if (transport == 
nullptr) {
   152     transport = makeDefaultTransport();
   153     BOOST_ASSERT(transport != 
nullptr);
   158     impl->ensureConnected(
false);
   170   auto id = m_impl->m_pendingInterestTable.allocateId();
   172   auto interest2 = make_shared<Interest>(interest);
   173   interest2->getNonce();
   176     impl->asyncExpressInterest(
id, interest2, afterSatisfied, afterNacked, afterTimeout);
   183 Face::cancelPendingInterest(
const PendingInterestId* pendingInterestId)
   186     impl->asyncRemovePendingInterest(reinterpret_cast<RecordId>(pendingInterestId));
   194     impl->asyncRemoveAllPendingInterests();
   201   return m_impl->m_pendingInterestTable.size();
   208     impl->asyncPutData(data);
   216     impl->asyncPutNack(nack);
   225   return setInterestFilter(filter, onInterest, 
nullptr, onFailure, signingInfo, flags);
   237   auto id = m_impl->registerPrefix(filter.
getPrefix(), onSuccess, onFailure, flags, options,
   245   auto id = m_impl->m_interestFilterTable.allocateId();
   248     impl->asyncSetInterestFilter(
id, filter, onInterest);
   255 Face::clearInterestFilter(
const InterestFilterId* interestFilterId)
   258     impl->asyncUnsetInterestFilter(reinterpret_cast<RecordId>(interestFilterId));
   272   auto id = m_impl->registerPrefix(prefix, onSuccess, onFailure, flags, options, 
nullopt, 
nullptr);
   277 Face::unregisterPrefixImpl(
const RegisteredPrefixId* registeredPrefixId,
   282     impl->asyncUnregisterPrefix(reinterpret_cast<RecordId>(registeredPrefixId),
   283                                 onSuccess, onFailure);
   290   if (m_ioService.stopped()) {
   295     if (timeout < time::milliseconds::zero()) {
   301     if (timeout > time::milliseconds::zero()) {
   302       m_impl->m_processEventsTimeoutEvent = m_impl->m_scheduler.schedule(timeout,
   303         [&io = m_ioService, &work = m_impl->m_ioServiceWork] {
   311       m_impl->m_ioServiceWork = make_unique<boost::asio::io_service::work>(m_ioService);
   327     if (m_transport->isConnected())
   328       m_transport->close();
   335 template<
typename NetPkt>
   339   addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
   340   addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
   344 Face::onReceiveElement(
const Block& blockFromDaemon)
   349   Buffer::const_iterator begin, end;
   351   Block netPacket(&*begin, std::distance(begin, end));
   352   switch (netPacket.type()) {
   354       auto interest = make_shared<Interest>(netPacket);
   356         auto nack = make_shared<lp::Nack>(
std::move(*interest));
   359         NDN_LOG_DEBUG(
">N " << nack->getInterest() << 
'~' << nack->getHeader().getReason());
   360         m_impl->nackPendingInterests(*nack);
   365         m_impl->processIncomingInterest(
std::move(interest));
   370       auto data = make_shared<Data>(netPacket);
   373       m_impl->satisfyPendingInterests(*data);
   380   : CancelHandle([&face, id] { face.cancelPendingInterest(
id); })
   385   : 
CancelHandle([&face, id] { face.unregisterPrefixImpl(
id, 
nullptr, 
nullptr); })
   397   if (m_id == 
nullptr) {
   398     if (onFailure != 
nullptr) {
   399       onFailure(
"RegisteredPrefixHandle is empty");
   404   m_face->unregisterPrefixImpl(m_id, onSuccess, onFailure);
   410   : 
CancelHandle([&face, id] { face.clearInterestFilter(
id); })
 #define NDN_THROW_NESTED(e)
virtual void doProcessEvents(time::milliseconds timeout, bool keepThread)
The interface of signing key management. 
function< void(const std::string &)> UnregisterPrefixFailureCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command fails. 
std::string to_string(const T &val)
void unregister(const UnregisterPrefixSuccessCallback &onSuccess=nullptr, const UnregisterPrefixFailureCallback &onFailure=nullptr)
Unregister the prefix. 
const Name & getPrefix() const
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression 
Represents a TLV element of NDN packet format. 
Represents an Interest packet. 
#define NDN_LOG_DEBUG(expression)
Log at DEBUG level. 
static void extractLpLocalFields(NetPkt &netPacket, const lp::Packet &lpPacket)
extract local fields from NDNLPv2 packet and tag onto a network layer packet 
Signing parameters passed to KeyChain. 
static shared_ptr< UnixTransport > create(const std::string &uri)
Create transport with parameters defined in URI. 
represents a Network Nack 
#define IO_CAPTURE_WEAK_IMPL(OP)
void removeAllPendingInterests()
Cancel all previously expressed Interests. 
FIELD::ValueType get(size_t index=0) const
RegisteredPrefixHandle registerPrefix(const Name &prefix, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
Register prefix with the connected NDN forwarder. 
contains options for ControlCommand execution 
A handle of pending Interest. 
static shared_ptr< TcpTransport > create(const std::string &uri)
Create transport with parameters defined in URI. 
size_t getNPendingInterests() const
Get number of pending Interests. 
void shutdown()
Shutdown face operations. 
Provide a communication channel with local or remote NDN forwarder. 
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. 
represents the underlying protocol and address used by a Face 
CommandOptions & setSigningInfo(const security::SigningInfo &signingInfo)
sets signing parameters 
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest. 
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter. 
#define IO_CAPTURE_WEAK_IMPL_END
const std::string & getScheme() const
get scheme (protocol) 
RegisteredPrefixHandle() noexcept
InterestFilterHandle() noexcept=default
System configuration file for NDN platform. 
function< void()> UnregisterPrefixSuccessCallback
Callback invoked when unregisterPrefix or unsetInterestFilter command succeeds. 
void put(Data data)
Publish data packet. 
OversizedPacketError(char pktType, const Name &name, size_t wireSize)
Constructor. 
A handle of registered Interest filter. 
PendingInterestHandle() noexcept=default
function< void(const Interest &)> TimeoutCallback
Callback invoked when expressed Interest times out. 
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback invoked when Nack is sent in response to expressed Interest. 
Represents a Data packet. 
RegisteredPrefixHandle setInterestFilter(const InterestFilter &filter, const InterestCallback &onInterest, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
Set InterestFilter to dispatch incoming matching interest to onInterest callback and register the fil...
const Parsed & getParsedConfiguration() const
Face(shared_ptr< Transport > transport=nullptr)
Create Face using given transport (or default transport if omitted) 
const nullopt_t nullopt((nullopt_t::init()))
A handle of registered prefix. 
function< void(const Interest &, const Data &)> DataCallback
Callback invoked when expressed Interest gets satisfied with a Data packet. 
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size