Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
| 11 | * |
| 12 | * Based on code originally written by Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 15 | #include "common.hpp" |
| 16 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 17 | #include "face.hpp" |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 18 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 19 | #include "security/signature-sha256-with-rsa.hpp" |
| 20 | |
| 21 | #include "util/time.hpp" |
| 22 | #include "util/random.hpp" |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 23 | #include "util/config-file.hpp" |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 24 | #include <cstdlib> |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 25 | |
| 26 | #include "management/ndnd-controller.hpp" |
| 27 | #include "management/nfd-controller.hpp" |
Alexander Afanasyev | efe3ab2 | 2014-02-19 14:57:50 -0800 | [diff] [blame] | 28 | #include "management/nrd-controller.hpp" |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 29 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 30 | namespace ndn { |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 32 | Face::Face() |
Jeff Thompson | fb29cda | 2013-08-24 10:26:54 -0700 | [diff] [blame] | 33 | { |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 34 | const std::string socketName = UnixTransport::getDefaultSocketName(m_config); |
| 35 | construct(shared_ptr<Transport>(new UnixTransport(socketName)), |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 36 | make_shared<boost::asio::io_service>()); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 37 | } |
| 38 | |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 39 | Face::Face(const shared_ptr<boost::asio::io_service>& ioService) |
| 40 | { |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 41 | const std::string socketName = UnixTransport::getDefaultSocketName(m_config); |
| 42 | construct(shared_ptr<Transport>(new UnixTransport(socketName)), |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 43 | ioService); |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 46 | class NullIoDeleter |
| 47 | { |
| 48 | public: |
| 49 | void |
| 50 | operator()(boost::asio::io_service*) |
| 51 | { |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | Face::Face(boost::asio::io_service& ioService) |
| 56 | { |
| 57 | const std::string socketName = UnixTransport::getDefaultSocketName(m_config); |
| 58 | construct(shared_ptr<Transport>(new UnixTransport(socketName)), |
| 59 | shared_ptr<boost::asio::io_service>(&ioService, NullIoDeleter())); |
| 60 | } |
| 61 | |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 62 | Face::Face(const std::string& host, const std::string& port/* = "6363"*/) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 63 | { |
| 64 | construct(shared_ptr<Transport>(new TcpTransport(host, port)), |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 65 | make_shared<boost::asio::io_service>()); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 68 | Face::Face(const shared_ptr<Transport>& transport) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 69 | { |
| 70 | construct(transport, |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 71 | make_shared<boost::asio::io_service>()); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | Face::Face(const shared_ptr<Transport>& transport, |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 75 | boost::asio::io_service& ioService) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 76 | { |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 77 | construct(transport, |
| 78 | shared_ptr<boost::asio::io_service>(&ioService, NullIoDeleter())); |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 81 | void |
| 82 | Face::setController(const shared_ptr<Controller>& controller) |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 83 | { |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 84 | m_fwController = controller; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void |
| 88 | Face::construct(const shared_ptr<Transport>& transport, |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 89 | const shared_ptr<boost::asio::io_service>& ioService) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 90 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 91 | m_pitTimeoutCheckTimerActive = false; |
| 92 | m_transport = transport; |
| 93 | m_ioService = ioService; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 94 | |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 95 | m_pitTimeoutCheckTimer = make_shared<monotonic_deadline_timer>(ref(*m_ioService)); |
| 96 | m_processEventsTimeoutTimer = make_shared<monotonic_deadline_timer>(ref(*m_ioService)); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 97 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 98 | std::string protocol = "nrd-0.1"; |
| 99 | |
| 100 | try |
Alexander Afanasyev | efe3ab2 | 2014-02-19 14:57:50 -0800 | [diff] [blame] | 101 | { |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 102 | protocol = m_config.getParsedConfiguration().get<std::string>("protocol"); |
| 103 | } |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 104 | catch (boost::property_tree::ptree_bad_path& error) |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 105 | { |
| 106 | // protocol not specified |
| 107 | } |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 108 | catch (boost::property_tree::ptree_bad_data& error) |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 109 | { |
| 110 | throw ConfigFile::Error(error.what()); |
| 111 | } |
| 112 | |
| 113 | if (isSupportedNrdProtocol(protocol)) |
| 114 | { |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 115 | m_fwController = make_shared<nrd::Controller>(ref(*this)); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 116 | } |
Steve DiBenedetto | acab880 | 2014-03-24 11:15:57 -0600 | [diff] [blame] | 117 | else if (isSupportedNfdProtocol(protocol)) |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 118 | { |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 119 | m_fwController = make_shared<nfd::Controller>(ref(*this)); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 120 | } |
| 121 | else if (isSupportedNdndProtocol(protocol)) |
| 122 | { |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 123 | m_fwController = make_shared<ndnd::Controller>(ref(*this)); |
Alexander Afanasyev | efe3ab2 | 2014-02-19 14:57:50 -0800 | [diff] [blame] | 124 | } |
Jeff Thompson | fb29cda | 2013-08-24 10:26:54 -0700 | [diff] [blame] | 125 | else |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 126 | { |
| 127 | throw Face::Error("Cannot create controller for unsupported protocol \"" + protocol + "\""); |
| 128 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 131 | const PendingInterestId* |
| 132 | Face::expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout) |
| 133 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 134 | if (!m_transport->isConnected()) |
| 135 | m_transport->connect(*m_ioService, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 136 | bind(&Face::onReceiveElement, this, _1)); |
| 137 | |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 138 | shared_ptr<Interest> interestToExpress(new Interest(interest)); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 139 | |
Alexander Afanasyev | 4e50b97 | 2014-03-25 10:57:50 -0700 | [diff] [blame] | 140 | // If the same ioService thread, dispatch directly calls the method |
| 141 | m_ioService->dispatch(bind(&Face::asyncExpressInterest, this, |
| 142 | interestToExpress, onData, onTimeout)); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 143 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 144 | return reinterpret_cast<const PendingInterestId*>(interestToExpress.get()); |
| 145 | } |
| 146 | |
| 147 | const PendingInterestId* |
| 148 | Face::expressInterest(const Name& name, |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 149 | const Interest& tmpl, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 150 | const OnData& onData, const OnTimeout& onTimeout/* = OnTimeout()*/) |
| 151 | { |
| 152 | return expressInterest(Interest(name, |
| 153 | tmpl.getMinSuffixComponents(), |
| 154 | tmpl.getMaxSuffixComponents(), |
| 155 | tmpl.getExclude(), |
| 156 | tmpl.getChildSelector(), |
| 157 | tmpl.getMustBeFresh(), |
| 158 | tmpl.getScope(), |
| 159 | tmpl.getInterestLifetime()), |
| 160 | onData, onTimeout); |
| 161 | } |
| 162 | |
| 163 | void |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 164 | Face::asyncExpressInterest(const shared_ptr<const Interest>& interest, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 165 | const OnData& onData, const OnTimeout& onTimeout) |
| 166 | { |
Alexander Afanasyev | 4e50b97 | 2014-03-25 10:57:50 -0700 | [diff] [blame] | 167 | if (!m_transport->isExpectingData()) |
| 168 | m_transport->resume(); |
| 169 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 170 | m_pendingInterestTable.push_back(shared_ptr<PendingInterest>(new PendingInterest |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 171 | (interest, onData, onTimeout))); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 172 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 173 | if (!interest->getLocalControlHeader().empty(false, true)) |
| 174 | { |
| 175 | // encode only NextHopFaceId towards the forwarder |
| 176 | m_transport->send(interest->getLocalControlHeader().wireEncode(*interest, false, true), |
| 177 | interest->wireEncode()); |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | m_transport->send(interest->wireEncode()); |
| 182 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 183 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 184 | if (!m_pitTimeoutCheckTimerActive) { |
| 185 | m_pitTimeoutCheckTimerActive = true; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 186 | m_pitTimeoutCheckTimer->expires_from_now(time::milliseconds(100)); |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 187 | m_pitTimeoutCheckTimer->async_wait(bind(&Face::checkPitExpire, this)); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 188 | } |
| 189 | } |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 190 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 191 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 192 | Face::put(const Data& data) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 193 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 194 | if (!m_transport->isConnected()) |
| 195 | m_transport->connect(*m_ioService, |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 196 | bind(&Face::onReceiveElement, this, _1)); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 197 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 198 | if (!data.getLocalControlHeader().empty(false, true)) |
| 199 | { |
Alexander Afanasyev | 8301835 | 2014-02-18 19:52:15 -0800 | [diff] [blame] | 200 | m_transport->send(data.getLocalControlHeader().wireEncode(data, false, true), |
| 201 | data.wireEncode()); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 202 | } |
| 203 | else |
| 204 | { |
Alexander Afanasyev | 8301835 | 2014-02-18 19:52:15 -0800 | [diff] [blame] | 205 | m_transport->send(data.wireEncode()); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 206 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 209 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 210 | Face::removePendingInterest(const PendingInterestId* pendingInterestId) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 211 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 212 | m_ioService->post(bind(&Face::asyncRemovePendingInterest, this, pendingInterestId)); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | |
| 216 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 217 | Face::asyncRemovePendingInterest(const PendingInterestId* pendingInterestId) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 218 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 219 | m_pendingInterestTable.remove_if(MatchPendingInterestId(pendingInterestId)); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 223 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 224 | const OnInterest& onInterest, |
| 225 | const OnSetInterestFilterFailed& onSetInterestFilterFailed) |
| 226 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 227 | shared_ptr<InterestFilterRecord> filter = |
| 228 | make_shared<InterestFilterRecord>(cref(interestFilter), onInterest); |
| 229 | shared_ptr<RegisteredPrefix> prefixToRegister = |
| 230 | make_shared<RegisteredPrefix>(cref(interestFilter.getPrefix()), filter); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 231 | |
| 232 | m_fwController->selfRegisterPrefix(prefixToRegister->getPrefix(), |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 233 | bind(&Face::afterPrefixRegistered, this, prefixToRegister), |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 234 | bind(onSetInterestFilterFailed, |
| 235 | prefixToRegister->getPrefix(), _1)); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 236 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 237 | return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get()); |
| 238 | } |
| 239 | |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 240 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 241 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 242 | const OnInterest& onInterest, |
| 243 | const OnSetInterestFilterFailed& onSetInterestFilterFailed, |
| 244 | const IdentityCertificate& certificate) |
| 245 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 246 | shared_ptr<InterestFilterRecord> filter = |
| 247 | make_shared<InterestFilterRecord>(cref(interestFilter), onInterest); |
| 248 | shared_ptr<RegisteredPrefix> prefixToRegister = |
| 249 | make_shared<RegisteredPrefix>(cref(interestFilter.getPrefix()), filter); |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 250 | |
| 251 | m_fwController->selfRegisterPrefix(prefixToRegister->getPrefix(), |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 252 | bind(&Face::afterPrefixRegistered, this, prefixToRegister), |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 253 | bind(onSetInterestFilterFailed, |
| 254 | prefixToRegister->getPrefix(), _1), |
| 255 | certificate); |
| 256 | |
| 257 | return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get()); |
| 258 | } |
| 259 | |
| 260 | const RegisteredPrefixId* |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 261 | Face::setInterestFilter(const InterestFilter& interestFilter, |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 262 | const OnInterest& onInterest, |
| 263 | const OnSetInterestFilterFailed& onSetInterestFilterFailed, |
| 264 | const Name& identity) |
| 265 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 266 | // without ptr_lib:: here, reference to cref becomes ambiguous on OSX 10.9 |
| 267 | shared_ptr<InterestFilterRecord> filter = |
| 268 | make_shared<InterestFilterRecord>(cref(interestFilter), onInterest); |
| 269 | shared_ptr<RegisteredPrefix> prefixToRegister = |
| 270 | make_shared<RegisteredPrefix>(cref(interestFilter.getPrefix()), filter); |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 271 | |
| 272 | m_fwController->selfRegisterPrefix(prefixToRegister->getPrefix(), |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 273 | bind(&Face::afterPrefixRegistered, this, prefixToRegister), |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 274 | bind(onSetInterestFilterFailed, |
| 275 | prefixToRegister->getPrefix(), _1), |
| 276 | identity); |
| 277 | |
| 278 | return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get()); |
| 279 | } |
| 280 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 281 | void |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 282 | Face::afterPrefixRegistered(const shared_ptr<RegisteredPrefix>& registeredPrefix) |
| 283 | { |
| 284 | m_registeredPrefixTable.push_back(registeredPrefix); |
| 285 | |
| 286 | if (static_cast<bool>(registeredPrefix->getFilter())) |
| 287 | { |
| 288 | // it was a combined operation |
| 289 | m_interestFilterTable.push_back(registeredPrefix->getFilter()); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 294 | Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 295 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 296 | m_ioService->post(bind(&Face::asyncUnsetInterestFilter, this, registeredPrefixId)); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | void |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 300 | Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId, |
| 301 | const IdentityCertificate& certificate) |
| 302 | { |
| 303 | m_ioService->post(bind(&Face::asyncUnsetInterestFilterWithCertificate, this, |
| 304 | registeredPrefixId, certificate)); |
| 305 | } |
| 306 | |
| 307 | void |
| 308 | Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId, |
| 309 | const Name& identity) |
| 310 | { |
| 311 | m_ioService->post(bind(&Face::asyncUnsetInterestFilterWithIdentity, this, |
| 312 | registeredPrefixId, identity)); |
| 313 | } |
| 314 | |
| 315 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 316 | Face::asyncUnsetInterestFilter(const RegisteredPrefixId* registeredPrefixId) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 317 | { |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 318 | RegisteredPrefixTable::iterator i = std::find_if(m_registeredPrefixTable.begin(), |
| 319 | m_registeredPrefixTable.end(), |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 320 | MatchRegisteredPrefixId(registeredPrefixId)); |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 321 | if (i != m_registeredPrefixTable.end()) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 322 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 323 | const shared_ptr<InterestFilterRecord>& filter = (*i)->getFilter(); |
| 324 | if (static_cast<bool>(filter)) |
| 325 | { |
| 326 | // it was a combined operation |
| 327 | m_interestFilterTable.remove(filter); |
| 328 | } |
| 329 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 330 | m_fwController->selfDeregisterPrefix((*i)->getPrefix(), |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 331 | bind(&Face::finalizeUnregisterPrefix, this, i), |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 332 | Controller::FailCallback()); |
| 333 | } |
| 334 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 335 | // there cannot be two registered prefixes with the same id |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Alexander Afanasyev | 12dfbad | 2014-02-11 14:42:46 -0800 | [diff] [blame] | 338 | void |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 339 | Face::asyncUnsetInterestFilterWithCertificate(const RegisteredPrefixId* registeredPrefixId, |
| 340 | const IdentityCertificate& certificate) |
| 341 | { |
| 342 | RegisteredPrefixTable::iterator i = std::find_if(m_registeredPrefixTable.begin(), |
| 343 | m_registeredPrefixTable.end(), |
| 344 | MatchRegisteredPrefixId(registeredPrefixId)); |
| 345 | if (i != m_registeredPrefixTable.end()) |
| 346 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 347 | const shared_ptr<InterestFilterRecord>& filter = (*i)->getFilter(); |
| 348 | if (static_cast<bool>(filter)) |
| 349 | { |
| 350 | // it was a combined operation |
| 351 | m_interestFilterTable.remove(filter); |
| 352 | } |
| 353 | |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 354 | m_fwController->selfDeregisterPrefix((*i)->getPrefix(), |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 355 | bind(&Face::finalizeUnregisterPrefix, this, i), |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 356 | Controller::FailCallback(), |
| 357 | certificate); |
| 358 | } |
| 359 | |
| 360 | // there cannot be two registered prefixes with the same id |
| 361 | } |
| 362 | |
| 363 | void |
| 364 | Face::asyncUnsetInterestFilterWithIdentity(const RegisteredPrefixId* registeredPrefixId, |
| 365 | const Name& identity) |
| 366 | { |
| 367 | RegisteredPrefixTable::iterator i = std::find_if(m_registeredPrefixTable.begin(), |
| 368 | m_registeredPrefixTable.end(), |
| 369 | MatchRegisteredPrefixId(registeredPrefixId)); |
| 370 | if (i != m_registeredPrefixTable.end()) |
| 371 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 372 | const shared_ptr<InterestFilterRecord>& filter = (*i)->getFilter(); |
| 373 | if (static_cast<bool>(filter)) |
| 374 | { |
| 375 | // it was a combined operation |
| 376 | m_interestFilterTable.remove(filter); |
| 377 | } |
| 378 | |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 379 | m_fwController->selfDeregisterPrefix((*i)->getPrefix(), |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 380 | bind(&Face::finalizeUnregisterPrefix, this, i), |
Yingdi Yu | e66bf2a | 2014-04-28 17:07:36 -0700 | [diff] [blame] | 381 | Controller::FailCallback(), |
| 382 | identity); |
| 383 | } |
| 384 | |
| 385 | // there cannot be two registered prefixes with the same id |
| 386 | } |
| 387 | |
| 388 | void |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 389 | Face::finalizeUnregisterPrefix(RegisteredPrefixTable::iterator item) |
Alexander Afanasyev | 12dfbad | 2014-02-11 14:42:46 -0800 | [diff] [blame] | 390 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 391 | m_registeredPrefixTable.erase(item); |
Alexander Afanasyev | 12dfbad | 2014-02-11 14:42:46 -0800 | [diff] [blame] | 392 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 393 | if (!m_pitTimeoutCheckTimerActive && m_registeredPrefixTable.empty()) |
Alexander Afanasyev | 12dfbad | 2014-02-11 14:42:46 -0800 | [diff] [blame] | 394 | { |
Alexander Afanasyev | 52afb3f | 2014-03-07 09:05:35 +0000 | [diff] [blame] | 395 | m_transport->pause(); |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 396 | if (!m_ioServiceWork) { |
| 397 | m_processEventsTimeoutTimer->cancel(); |
Alexander Afanasyev | 12dfbad | 2014-02-11 14:42:46 -0800 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 402 | void |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 403 | Face::processEvents(const time::milliseconds& timeout/* = time::milliseconds::zero()*/, |
| 404 | bool keepThread/* = false*/) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 405 | { |
| 406 | try |
| 407 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 408 | if (timeout < time::milliseconds::zero()) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 409 | { |
| 410 | // do not block if timeout is negative, but process pending events |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 411 | m_ioService->poll(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 412 | return; |
| 413 | } |
| 414 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 415 | if (timeout > time::milliseconds::zero()) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 416 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 417 | m_processEventsTimeoutTimer->expires_from_now(time::milliseconds(timeout)); |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 418 | m_processEventsTimeoutTimer->async_wait(&fireProcessEventsTimeout); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 419 | } |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 420 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 421 | if (keepThread) { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 422 | // work will ensure that m_ioService is running until work object exists |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 423 | m_ioServiceWork = make_shared<boost::asio::io_service::work>(ref(*m_ioService)); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 424 | } |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 425 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 426 | m_ioService->run(); |
| 427 | m_ioService->reset(); // so it is possible to run processEvents again (if necessary) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 428 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 429 | catch (Face::ProcessEventsTimeout&) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 430 | { |
| 431 | // break |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 432 | m_ioService->reset(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 433 | } |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 434 | catch (std::exception&) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 435 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 436 | m_ioService->reset(); |
| 437 | m_pendingInterestTable.clear(); |
| 438 | m_registeredPrefixTable.clear(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 439 | throw; |
| 440 | } |
Jeff Thompson | fb29cda | 2013-08-24 10:26:54 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 443 | void |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 444 | Face::shutdown() |
Jeff Thompson | 517ffa8 | 2013-08-05 16:04:34 -0700 | [diff] [blame] | 445 | { |
Alexander Afanasyev | 7dced46 | 2014-03-19 15:12:32 -0700 | [diff] [blame] | 446 | m_ioService->post(bind(&Face::asyncShutdown, this)); |
| 447 | } |
| 448 | |
| 449 | void |
| 450 | Face::asyncShutdown() |
| 451 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 452 | m_pendingInterestTable.clear(); |
| 453 | m_registeredPrefixTable.clear(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 454 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 455 | m_transport->close(); |
| 456 | m_pitTimeoutCheckTimer->cancel(); |
| 457 | m_processEventsTimeoutTimer->cancel(); |
| 458 | m_pitTimeoutCheckTimerActive = false; |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 461 | void |
| 462 | Face::fireProcessEventsTimeout(const boost::system::error_code& error) |
| 463 | { |
| 464 | if (!error) // can fire for some other reason, e.g., cancelled |
| 465 | throw Face::ProcessEventsTimeout(); |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 466 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 467 | |
| 468 | void |
| 469 | Face::checkPitExpire() |
| 470 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 471 | // Check for PIT entry timeouts. |
| 472 | time::steady_clock::TimePoint now = time::steady_clock::now(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 473 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 474 | PendingInterestTable::iterator i = m_pendingInterestTable.begin(); |
| 475 | while (i != m_pendingInterestTable.end()) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 476 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 477 | if ((*i)->isTimedOut(now)) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 478 | { |
| 479 | // Save the PendingInterest and remove it from the PIT. Then call the callback. |
| 480 | shared_ptr<PendingInterest> pendingInterest = *i; |
| 481 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 482 | i = m_pendingInterestTable.erase(i); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 483 | |
| 484 | pendingInterest->callTimeout(); |
| 485 | } |
| 486 | else |
| 487 | ++i; |
| 488 | } |
| 489 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 490 | if (!m_pendingInterestTable.empty()) { |
| 491 | m_pitTimeoutCheckTimerActive = true; |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 492 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 493 | m_pitTimeoutCheckTimer->expires_from_now(time::milliseconds(100)); |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 494 | m_pitTimeoutCheckTimer->async_wait(bind(&Face::checkPitExpire, this)); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 495 | } |
| 496 | else { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 497 | m_pitTimeoutCheckTimerActive = false; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 498 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 499 | if (m_registeredPrefixTable.empty()) { |
Alexander Afanasyev | 52afb3f | 2014-03-07 09:05:35 +0000 | [diff] [blame] | 500 | m_transport->pause(); |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 501 | if (!m_ioServiceWork) { |
| 502 | m_processEventsTimeoutTimer->cancel(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 509 | void |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 510 | Face::onReceiveElement(const Block& blockFromDaemon) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 511 | { |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 512 | const Block& block = nfd::LocalControlHeader::getPayload(blockFromDaemon); |
| 513 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 514 | if (block.type() == Tlv::Interest) |
| 515 | { |
| 516 | shared_ptr<Interest> interest(new Interest()); |
| 517 | interest->wireDecode(block); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 518 | if (&block != &blockFromDaemon) |
| 519 | interest->getLocalControlHeader().wireDecode(blockFromDaemon); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 520 | |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 521 | processInterestFilters(*interest); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 522 | } |
| 523 | else if (block.type() == Tlv::Data) |
| 524 | { |
| 525 | shared_ptr<Data> data(new Data()); |
| 526 | data->wireDecode(block); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 527 | if (&block != &blockFromDaemon) |
| 528 | data->getLocalControlHeader().wireDecode(blockFromDaemon); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 529 | |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 530 | satisfyPendingInterests(*data); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 531 | |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 532 | if (m_pendingInterestTable.empty()) { |
| 533 | m_pitTimeoutCheckTimer->cancel(); // this will cause checkPitExpire invocation |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 534 | } |
| 535 | } |
Yingdi Yu | f9fa52f | 2014-02-06 12:27:32 -0800 | [diff] [blame] | 536 | // ignore any other type |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 539 | void |
| 540 | Face::satisfyPendingInterests(Data& data) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 541 | { |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 542 | for (PendingInterestTable::iterator i = m_pendingInterestTable.begin (); |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 543 | i != m_pendingInterestTable.end(); |
| 544 | ) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 545 | { |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 546 | if ((*i)->getInterest()->matchesData(data)) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 547 | { |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame] | 548 | // Copy pointers to the objects and remove the PIT entry before calling the callback. |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 549 | OnData onData = (*i)->getOnData(); |
| 550 | shared_ptr<const Interest> interest = (*i)->getInterest(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 551 | |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 552 | PendingInterestTable::iterator next = i; |
| 553 | ++next; |
| 554 | m_pendingInterestTable.erase(i); |
| 555 | i = next; |
| 556 | |
| 557 | if (static_cast<bool>(onData)) { |
| 558 | onData(*interest, data); |
| 559 | } |
| 560 | } |
| 561 | else |
| 562 | ++i; |
| 563 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 564 | } |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 565 | |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 566 | void |
| 567 | Face::processInterestFilters(Interest& interest) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 568 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 569 | for (InterestFilterTable::iterator i = m_interestFilterTable.begin(); |
| 570 | i != m_interestFilterTable.end(); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 571 | ++i) |
| 572 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 573 | if ((*i)->doesMatch(interest.getName())) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 574 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame^] | 575 | (**i)(interest); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 576 | } |
| 577 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | } // namespace ndn |