Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 22 | #include "face.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 23 | #include "detail/face-impl.hpp" |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 24 | |
Junxiao Shi | 468abc3 | 2014-11-04 09:12:47 -0700 | [diff] [blame] | 25 | #include "encoding/tlv.hpp" |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 26 | #include "net/face-uri.hpp" |
Junxiao Shi | c6acc7a | 2015-06-23 10:03:56 -0700 | [diff] [blame] | 27 | #include "security/signing-helpers.hpp" |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 28 | #include "util/random.hpp" |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 29 | #include "util/time.hpp" |
| 30 | |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 31 | #include "ns3/node-list.h" |
| 32 | #include "ns3/ndnSIM/helper/ndn-stack-helper.hpp" |
| 33 | #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp" |
| 34 | #include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp" |
| 35 | |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 36 | // NDN_LOG_INIT(ndn.Face) is declared in face-impl.hpp |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 37 | |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 38 | // A callback scheduled through io.post and io.dispatch may be invoked after the face |
| 39 | // is destructed. To prevent this situation, these macros captures Face::m_impl as weak_ptr, |
| 40 | // and skips callback execution if the face has been destructed. |
| 41 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 42 | #define IO_CAPTURE_WEAK_IMPL(OP) \ |
| 43 | { \ |
| 44 | weak_ptr<Impl> implWeak(m_impl); \ |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 45 | m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { \ |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 46 | auto impl = implWeak.lock(); \ |
| 47 | if (impl != nullptr) { |
| 48 | #define IO_CAPTURE_WEAK_IMPL_END \ |
| 49 | } \ |
| 50 | }); \ |
| 51 | } |
| 52 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 53 | namespace ndn { |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 54 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 55 | Face::OversizedPacketError::OversizedPacketError(char pktType, const Name& name, size_t wireSize) |
| 56 | : Error((pktType == 'I' ? "Interest " : pktType == 'D' ? "Data " : "Nack ") + |
| 57 | name.toUri() + " encodes into " + to_string(wireSize) + " octets, " |
| 58 | "exceeding the implementation limit of " + to_string(MAX_NDN_PACKET_SIZE) + " octets") |
| 59 | , pktType(pktType) |
| 60 | , name(name) |
| 61 | , wireSize(wireSize) |
| 62 | { |
| 63 | } |
| 64 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 65 | Face::Face(shared_ptr<Transport> transport) |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 66 | : m_impl(new Impl(*this)) |
Jeff Thompson | fb29cda | 2013-08-24 10:26:54 -0700 | [diff] [blame] | 67 | { |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 68 | construct(transport, ns3::ndn::StackHelper::getKeyChain()); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 71 | Face::Face(boost::asio::io_service& ioService) |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 72 | : m_impl(new Impl(*this)) |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 73 | { |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 74 | construct(nullptr, ns3::ndn::StackHelper::getKeyChain()); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 77 | Face::Face(shared_ptr<Transport> transport, KeyChain& keyChain) |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 78 | : m_impl(new Impl(*this)) |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 79 | { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 80 | construct(std::move(transport), keyChain); |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService) |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 84 | : m_impl(new Impl(*this)) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 85 | { |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 86 | construct(transport, ns3::ndn::StackHelper::getKeyChain()); |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Alexander Afanasyev | 8cf1c56 | 2016-06-23 16:01:55 -0700 | [diff] [blame] | 89 | Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain) |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 90 | : m_impl(new Impl(*this)) |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 91 | { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 92 | construct(std::move(transport), keyChain); |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 95 | shared_ptr<Transport> |
| 96 | Face::makeDefaultTransport() |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 97 | { |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 98 | ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext()); |
| 99 | NS_ASSERT_MSG(node->GetObject<ns3::ndn::L3Protocol>() != 0, |
| 100 | "NDN stack should be installed on the node " << node); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 101 | |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 102 | auto uri = ::nfd::FaceUri("ndnFace://" + boost::lexical_cast<std::string>(node->GetId())); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 103 | |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 104 | ::nfd::face::GenericLinkService::Options serviceOpts; |
| 105 | serviceOpts.allowLocalFields = true; |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 106 | |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 107 | auto nfdFace = make_shared<::nfd::Face>(make_unique<::nfd::face::GenericLinkService>(serviceOpts), |
| 108 | make_unique<::nfd::face::InternalForwarderTransport>(uri, uri)); |
| 109 | auto forwarderTransport = static_cast<::nfd::face::InternalForwarderTransport*>(nfdFace->getTransport()); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 110 | |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 111 | auto clientTransport = make_shared<::nfd::face::InternalClientTransport>(); |
| 112 | clientTransport->connectToForwarder(forwarderTransport); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 113 | |
Spyridon Mastorakis | 7bb7eb4 | 2016-11-28 18:03:05 -0800 | [diff] [blame] | 114 | node->GetObject<ns3::ndn::L3Protocol>()->addFace(nfdFace);; |
| 115 | |
| 116 | return clientTransport; |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 120 | Face::construct(shared_ptr<Transport> transport, KeyChain& keyChain) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 121 | { |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 122 | if (transport == nullptr) { |
| 123 | transport = makeDefaultTransport(); |
| 124 | } |
| 125 | BOOST_ASSERT(transport != nullptr); |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 126 | m_transport = std::move(transport); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 127 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 128 | m_nfdController = make_unique<nfd::Controller>(*this, keyChain); |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 129 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 130 | IO_CAPTURE_WEAK_IMPL(post) { |
| 131 | impl->ensureConnected(false); |
| 132 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Joao Pereira | 68c0d88 | 2015-05-19 14:27:55 -0400 | [diff] [blame] | 135 | Face::~Face() = default; |
Junxiao Shi | edd834e | 2014-10-28 20:28:58 -0700 | [diff] [blame] | 136 | |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 137 | shared_ptr<Transport> |
| 138 | Face::getTransport() |
| 139 | { |
| 140 | return m_transport; |
| 141 | } |
| 142 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 143 | const PendingInterestId* |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 144 | Face::expressInterest(const Interest& interest, |
| 145 | const DataCallback& afterSatisfied, |
| 146 | const NackCallback& afterNacked, |
| 147 | const TimeoutCallback& afterTimeout) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 148 | { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 149 | shared_ptr<Interest> interest2 = make_shared<Interest>(interest); |
| 150 | interest2->getNonce(); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 151 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 152 | IO_CAPTURE_WEAK_IMPL(dispatch) { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 153 | impl->asyncExpressInterest(interest2, afterSatisfied, afterNacked, afterTimeout); |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 154 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 155 | |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 156 | return reinterpret_cast<const PendingInterestId*>(interest2.get()); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 159 | void |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 160 | Face::removePendingInterest(const PendingInterestId* pendingInterestId) |
| 161 | { |
| 162 | IO_CAPTURE_WEAK_IMPL(post) { |
| 163 | impl->asyncRemovePendingInterest(pendingInterestId); |
| 164 | } IO_CAPTURE_WEAK_IMPL_END |
| 165 | } |
| 166 | |
| 167 | void |
| 168 | Face::removeAllPendingInterests() |
| 169 | { |
| 170 | IO_CAPTURE_WEAK_IMPL(post) { |
| 171 | impl->asyncRemoveAllPendingInterests(); |
| 172 | } IO_CAPTURE_WEAK_IMPL_END |
| 173 | } |
| 174 | |
| 175 | size_t |
| 176 | Face::getNPendingInterests() const |
| 177 | { |
| 178 | return m_impl->m_pendingInterestTable.size(); |
| 179 | } |
| 180 | |
| 181 | void |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 182 | Face::put(Data data) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 183 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 184 | IO_CAPTURE_WEAK_IMPL(dispatch) { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 185 | impl->asyncPutData(data); |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 186 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 189 | void |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 190 | Face::put(lp::Nack nack) |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 191 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 192 | IO_CAPTURE_WEAK_IMPL(dispatch) { |
Junxiao Shi | b6e276f | 2017-08-14 20:10:04 +0000 | [diff] [blame] | 193 | impl->asyncPutNack(nack); |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 194 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 6fcdde2 | 2014-08-22 19:03:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 197 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 198 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 199 | const InterestCallback& onInterest, |
| 200 | const RegisterPrefixFailureCallback& onFailure, |
| 201 | const security::SigningInfo& signingInfo, |
| 202 | uint64_t flags) |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 203 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 204 | return setInterestFilter(interestFilter, onInterest, nullptr, onFailure, signingInfo, flags); |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 208 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 209 | const InterestCallback& onInterest, |
| 210 | const RegisterPrefixSuccessCallback& onSuccess, |
| 211 | const RegisterPrefixFailureCallback& onFailure, |
| 212 | const security::SigningInfo& signingInfo, |
| 213 | uint64_t flags) |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 214 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 215 | auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 216 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 217 | nfd::CommandOptions options; |
| 218 | options.setSigningInfo(signingInfo); |
Junxiao Shi | 388ec25 | 2014-11-02 15:19:57 -0700 | [diff] [blame] | 219 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 220 | return m_impl->registerPrefix(interestFilter.getPrefix(), filter, |
| 221 | onSuccess, onFailure, flags, options); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 224 | const InterestFilterId* |
| 225 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 226 | const InterestCallback& onInterest) |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 227 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 228 | auto filter = make_shared<InterestFilterRecord>(interestFilter, onInterest); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 229 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 230 | IO_CAPTURE_WEAK_IMPL(post) { |
| 231 | impl->asyncSetInterestFilter(filter); |
| 232 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 233 | |
| 234 | return reinterpret_cast<const InterestFilterId*>(filter.get()); |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 237 | const RegisteredPrefixId* |
| 238 | Face::registerPrefix(const Name& prefix, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 239 | const RegisterPrefixSuccessCallback& onSuccess, |
| 240 | const RegisterPrefixFailureCallback& onFailure, |
| 241 | const security::SigningInfo& signingInfo, |
| 242 | uint64_t flags) |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 243 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 244 | nfd::CommandOptions options; |
| 245 | options.setSigningInfo(signingInfo); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 246 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 247 | return m_impl->registerPrefix(prefix, nullptr, onSuccess, onFailure, flags, options); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 248 | } |
| 249 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 250 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 251 | Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 252 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 253 | IO_CAPTURE_WEAK_IMPL(post) { |
| 254 | impl->asyncUnregisterPrefix(registeredPrefixId, nullptr, nullptr); |
| 255 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 258 | void |
| 259 | Face::unsetInterestFilter(const InterestFilterId* interestFilterId) |
| 260 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 261 | IO_CAPTURE_WEAK_IMPL(post) { |
| 262 | impl->asyncUnsetInterestFilter(interestFilterId); |
| 263 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 264 | } |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 265 | |
| 266 | void |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 267 | Face::unregisterPrefix(const RegisteredPrefixId* registeredPrefixId, |
| 268 | const UnregisterPrefixSuccessCallback& onSuccess, |
| 269 | const UnregisterPrefixFailureCallback& onFailure) |
| 270 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 271 | IO_CAPTURE_WEAK_IMPL(post) { |
| 272 | impl->asyncUnregisterPrefix(registeredPrefixId, onSuccess, onFailure); |
| 273 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 276 | void |
Junxiao Shi | 2ed9e07 | 2017-08-13 16:45:48 +0000 | [diff] [blame] | 277 | Face::doProcessEvents(time::milliseconds timeout, bool keepThread) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 278 | { |
Jeff Thompson | fb29cda | 2013-08-24 10:26:54 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 281 | void |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 282 | Face::shutdown() |
Jeff Thompson | 517ffa8 | 2013-08-05 16:04:34 -0700 | [diff] [blame] | 283 | { |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 284 | IO_CAPTURE_WEAK_IMPL(post) { |
| 285 | this->asyncShutdown(); |
| 286 | } IO_CAPTURE_WEAK_IMPL_END |
Alexander Afanasyev | 7dced46 | 2014-03-19 15:12:32 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void |
| 290 | Face::asyncShutdown() |
| 291 | { |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 292 | m_impl->m_pendingInterestTable.clear(); |
| 293 | m_impl->m_registeredPrefixTable.clear(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 294 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 295 | if (m_transport->isConnected()) |
| 296 | m_transport->close(); |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 299 | /** |
| 300 | * @brief extract local fields from NDNLPv2 packet and tag onto a network layer packet |
| 301 | */ |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 302 | template<typename NetPkt> |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 303 | static void |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 304 | extractLpLocalFields(NetPkt& netPacket, const lp::Packet& lpPacket) |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 305 | { |
Junxiao Shi | b38e6d4 | 2017-08-16 16:15:28 +0000 | [diff] [blame] | 306 | addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket); |
| 307 | addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket); |
Spyridon Mastorakis | e1ae096 | 2016-12-06 15:21:44 -0800 | [diff] [blame] | 308 | |
| 309 | if (lpPacket.has<lp::HopCountTagField>()) { |
| 310 | netPacket.setTag(make_shared<lp::HopCountTag>(lpPacket.get<lp::HopCountTagField>() + 1)); |
| 311 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 314 | void |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 315 | Face::onReceiveElement(const Block& blockFromDaemon) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 316 | { |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 317 | lp::Packet lpPacket(blockFromDaemon); // bare Interest/Data is a valid lp::Packet, |
| 318 | // no need to distinguish |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 319 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 320 | Buffer::const_iterator begin, end; |
| 321 | std::tie(begin, end) = lpPacket.get<lp::FragmentField>(); |
| 322 | Block netPacket(&*begin, std::distance(begin, end)); |
| 323 | switch (netPacket.type()) { |
| 324 | case tlv::Interest: { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 325 | auto interest = make_shared<Interest>(netPacket); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 326 | if (lpPacket.has<lp::NackField>()) { |
| 327 | auto nack = make_shared<lp::Nack>(std::move(*interest)); |
| 328 | nack->setHeader(lpPacket.get<lp::NackField>()); |
| 329 | extractLpLocalFields(*nack, lpPacket); |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 330 | NDN_LOG_DEBUG(">N " << nack->getInterest() << '~' << nack->getHeader().getReason()); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 331 | m_impl->nackPendingInterests(*nack); |
| 332 | } |
| 333 | else { |
| 334 | extractLpLocalFields(*interest, lpPacket); |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 335 | NDN_LOG_DEBUG(">I " << *interest); |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 336 | m_impl->processIncomingInterest(std::move(interest)); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 337 | } |
| 338 | break; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 339 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 340 | case tlv::Data: { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 341 | auto data = make_shared<Data>(netPacket); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 342 | extractLpLocalFields(*data, lpPacket); |
Junxiao Shi | 4460e82 | 2017-08-07 22:02:45 +0000 | [diff] [blame] | 343 | NDN_LOG_DEBUG(">D " << data->getName()); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 344 | m_impl->satisfyPendingInterests(*data); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 345 | break; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 346 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 347 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 350 | } // namespace ndn |