blob: aa25e8d2483205933ca707a719f2d27c454d4709 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -07005 * See COPYING for copyright and distribution information.
6 */
7
Alexander Afanasyev0222fba2014-02-09 23:16:02 -08008#include "common.hpp"
9
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080010#include "face.hpp"
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070011
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080012#include "security/signature-sha256-with-rsa.hpp"
13
14#include "util/time.hpp"
15#include "util/random.hpp"
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080016#include <cstdlib>
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080017
18#include "management/ndnd-controller.hpp"
19#include "management/nfd-controller.hpp"
Alexander Afanasyevefe3ab22014-02-19 14:57:50 -080020#include "management/nrd-controller.hpp"
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070021
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070022namespace ndn {
Alexander Afanasyevb790d952014-01-24 12:07:53 -080023
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080024Face::Face()
Jeff Thompsonfb29cda2013-08-24 10:26:54 -070025{
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080026 construct(shared_ptr<Transport>(new UnixTransport()),
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080027 make_shared<boost::asio::io_service>(),
28 shared_ptr<Controller>());
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080029}
30
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080031Face::Face(const shared_ptr<Controller>& controller)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080032{
33 construct(shared_ptr<Transport>(new UnixTransport()),
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080034 make_shared<boost::asio::io_service>(),
35 controller);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080036}
37
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080038Face::Face(const shared_ptr<boost::asio::io_service>& ioService)
39{
40 construct(shared_ptr<Transport>(new UnixTransport()),
41 ioService,
42 shared_ptr<Controller>());
43}
44
45Face::Face(const std::string& host, const std::string& port/* = "6363"*/)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080046{
47 construct(shared_ptr<Transport>(new TcpTransport(host, port)),
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080048 make_shared<boost::asio::io_service>(),
49 shared_ptr<Controller>());
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080050}
51
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080052Face::Face(const shared_ptr<Transport>& transport)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080053{
54 construct(transport,
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080055 make_shared<boost::asio::io_service>(),
56 shared_ptr<Controller>());
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080057}
58
59Face::Face(const shared_ptr<Transport>& transport,
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080060 const shared_ptr<boost::asio::io_service>& ioService)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080061{
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080062 construct(transport, ioService, shared_ptr<Controller>());
63}
64
65Face::Face(const shared_ptr<Transport>& transport,
66 const shared_ptr<boost::asio::io_service>& ioService,
67 const shared_ptr<Controller>& controller)
68{
69 construct(transport, ioService, controller);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080070}
71
72void
73Face::construct(const shared_ptr<Transport>& transport,
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080074 const shared_ptr<boost::asio::io_service>& ioService,
75 const shared_ptr<Controller>& controller)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080076{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -080077 m_pitTimeoutCheckTimerActive = false;
78 m_transport = transport;
79 m_ioService = ioService;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080080
Alexander Afanasyevf39c5372014-02-17 19:42:56 -080081 m_pitTimeoutCheckTimer = make_shared<boost::asio::deadline_timer>(boost::ref(*m_ioService));
82 m_processEventsTimeoutTimer = make_shared<boost::asio::deadline_timer>(boost::ref(*m_ioService));
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -080083
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080084 if (static_cast<bool>(controller))
Alexander Afanasyevefe3ab22014-02-19 14:57:50 -080085 {
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080086 m_fwController = controller;
Alexander Afanasyevefe3ab22014-02-19 14:57:50 -080087 }
Jeff Thompsonfb29cda2013-08-24 10:26:54 -070088 else
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -080089 {
90 if (std::getenv("NFD") != 0)
91 {
92 if (std::getenv("NRD") != 0)
93 m_fwController = make_shared<nrd::Controller>(boost::ref(*this));
94 else
95 m_fwController = make_shared<nfd::Controller>(boost::ref(*this));
96 }
97 else
98 m_fwController = make_shared<ndnd::Controller>(boost::ref(*this));
99 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800100}
101
102
103const PendingInterestId*
104Face::expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout)
105{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800106 if (!m_transport->isConnected())
107 m_transport->connect(*m_ioService,
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800108 bind(&Face::onReceiveElement, this, _1));
109
110 shared_ptr<const Interest> interestToExpress(new Interest(interest));
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800111
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800112 m_ioService->post(bind(&Face::asyncExpressInterest, this, interestToExpress, onData, onTimeout));
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800113
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800114 return reinterpret_cast<const PendingInterestId*>(interestToExpress.get());
115}
116
117const PendingInterestId*
118Face::expressInterest(const Name& name,
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800119 const Interest& tmpl,
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800120 const OnData& onData, const OnTimeout& onTimeout/* = OnTimeout()*/)
121{
122 return expressInterest(Interest(name,
123 tmpl.getMinSuffixComponents(),
124 tmpl.getMaxSuffixComponents(),
125 tmpl.getExclude(),
126 tmpl.getChildSelector(),
127 tmpl.getMustBeFresh(),
128 tmpl.getScope(),
129 tmpl.getInterestLifetime()),
130 onData, onTimeout);
131}
132
133void
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800134Face::asyncExpressInterest(const shared_ptr<const Interest>& interest,
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800135 const OnData& onData, const OnTimeout& onTimeout)
136{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800137 m_pendingInterestTable.push_back(shared_ptr<PendingInterest>(new PendingInterest
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800138 (interest, onData, onTimeout)));
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800139
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800140 if (!interest->getLocalControlHeader().empty(false, true))
141 {
142 // encode only NextHopFaceId towards the forwarder
143 m_transport->send(interest->getLocalControlHeader().wireEncode(*interest, false, true),
144 interest->wireEncode());
145 }
146 else
147 {
148 m_transport->send(interest->wireEncode());
149 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800150
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800151 if (!m_pitTimeoutCheckTimerActive) {
152 m_pitTimeoutCheckTimerActive = true;
153 m_pitTimeoutCheckTimer->expires_from_now(boost::posix_time::milliseconds(100));
154 m_pitTimeoutCheckTimer->async_wait(bind(&Face::checkPitExpire, this));
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800155 }
156}
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800157
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800158void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800159Face::put(const Data& data)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800160{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800161 if (!m_transport->isConnected())
162 m_transport->connect(*m_ioService,
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800163 bind(&Face::onReceiveElement, this, _1));
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800164
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800165 if (!data.getLocalControlHeader().empty(false, true))
166 {
Alexander Afanasyev83018352014-02-18 19:52:15 -0800167 m_transport->send(data.getLocalControlHeader().wireEncode(data, false, true),
168 data.wireEncode());
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800169 }
170 else
171 {
Alexander Afanasyev83018352014-02-18 19:52:15 -0800172 m_transport->send(data.wireEncode());
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800173 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800174}
175
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800176void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800177Face::removePendingInterest(const PendingInterestId* pendingInterestId)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800178{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800179 m_ioService->post(bind(&Face::asyncRemovePendingInterest, this, pendingInterestId));
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800180}
181
182
183void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800184Face::asyncRemovePendingInterest(const PendingInterestId* pendingInterestId)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800185{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800186 m_pendingInterestTable.remove_if(MatchPendingInterestId(pendingInterestId));
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800187}
188
189const RegisteredPrefixId*
190Face::setInterestFilter(const Name& prefix,
191 const OnInterest& onInterest,
192 const OnSetInterestFilterFailed& onSetInterestFilterFailed)
193{
194 shared_ptr<RegisteredPrefix> prefixToRegister(new RegisteredPrefix(prefix, onInterest));
195
196 m_fwController->selfRegisterPrefix(prefixToRegister->getPrefix(),
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800197 bind(&RegisteredPrefixTable::push_back, &m_registeredPrefixTable, prefixToRegister),
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800198 bind(onSetInterestFilterFailed, prefixToRegister->getPrefix(), _1));
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800199
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800200 return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get());
201}
202
203void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800204Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800205{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800206 m_ioService->post(bind(&Face::asyncUnsetInterestFilter, this, registeredPrefixId));
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800207}
208
209void
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800210Face::asyncUnsetInterestFilter(const RegisteredPrefixId* registeredPrefixId)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800211{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800212 RegisteredPrefixTable::iterator i = std::find_if(m_registeredPrefixTable.begin(), m_registeredPrefixTable.end(),
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800213 MatchRegisteredPrefixId(registeredPrefixId));
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800214 if (i != m_registeredPrefixTable.end())
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800215 {
216 m_fwController->selfDeregisterPrefix((*i)->getPrefix(),
Alexander Afanasyev12dfbad2014-02-11 14:42:46 -0800217 bind(&Face::finalizeUnsertInterestFilter, this, i),
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800218 Controller::FailCallback());
219 }
220
221 // there cannot be two registered prefixes with the same id. if there are, then something is broken
222}
223
Alexander Afanasyev12dfbad2014-02-11 14:42:46 -0800224void
225Face::finalizeUnsertInterestFilter(RegisteredPrefixTable::iterator item)
226{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800227 m_registeredPrefixTable.erase(item);
Alexander Afanasyev12dfbad2014-02-11 14:42:46 -0800228
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800229 if (!m_pitTimeoutCheckTimerActive && m_registeredPrefixTable.empty())
Alexander Afanasyev12dfbad2014-02-11 14:42:46 -0800230 {
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800231 m_transport->close();
232 if (!m_ioServiceWork) {
233 m_processEventsTimeoutTimer->cancel();
Alexander Afanasyev12dfbad2014-02-11 14:42:46 -0800234 }
235 }
236}
237
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800238void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800239Face::processEvents(Milliseconds timeout/* = 0 */, bool keepThread/* = false*/)
240{
241 try
242 {
243 if (timeout < 0)
244 {
245 // do not block if timeout is negative, but process pending events
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800246 m_ioService->poll();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800247 return;
248 }
249
250 if (timeout > 0)
251 {
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800252 m_processEventsTimeoutTimer->expires_from_now(boost::posix_time::milliseconds(timeout));
253 m_processEventsTimeoutTimer->async_wait(&fireProcessEventsTimeout);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800254 }
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800255
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800256 if (keepThread) {
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800257 // work will ensure that m_ioService is running until work object exists
258 m_ioServiceWork = make_shared<boost::asio::io_service::work>(boost::ref(*m_ioService));
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800259 }
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800260
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800261 m_ioService->run();
262 m_ioService->reset(); // so it is possible to run processEvents again (if necessary)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800263 }
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800264 catch(Face::ProcessEventsTimeout&)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800265 {
266 // break
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800267 m_ioService->reset();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800268 }
Alexander Afanasyev7682ccb2014-02-20 10:29:35 -0800269 catch(const std::exception&)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800270 {
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800271 m_ioService->reset();
272 m_pendingInterestTable.clear();
273 m_registeredPrefixTable.clear();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800274 throw;
275 }
Jeff Thompsonfb29cda2013-08-24 10:26:54 -0700276}
277
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800278void
Jeff Thompson0050abe2013-09-17 12:50:25 -0700279Face::shutdown()
Jeff Thompson517ffa82013-08-05 16:04:34 -0700280{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800281 m_pendingInterestTable.clear();
282 m_registeredPrefixTable.clear();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800283
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800284 m_transport->close();
285 m_pitTimeoutCheckTimer->cancel();
286 m_processEventsTimeoutTimer->cancel();
287 m_pitTimeoutCheckTimerActive = false;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700288}
289
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800290void
291Face::fireProcessEventsTimeout(const boost::system::error_code& error)
292{
293 if (!error) // can fire for some other reason, e.g., cancelled
294 throw Face::ProcessEventsTimeout();
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -0700295}
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800296
297void
298Face::checkPitExpire()
299{
300 // Check for PIT entry timeouts. Go backwards through the list so we can erase entries.
301 MillisecondsSince1970 nowMilliseconds = getNowMilliseconds();
302
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800303 PendingInterestTable::iterator i = m_pendingInterestTable.begin();
304 while (i != m_pendingInterestTable.end())
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800305 {
306 if ((*i)->isTimedOut(nowMilliseconds))
307 {
308 // Save the PendingInterest and remove it from the PIT. Then call the callback.
309 shared_ptr<PendingInterest> pendingInterest = *i;
310
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800311 i = m_pendingInterestTable.erase(i);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800312
313 pendingInterest->callTimeout();
314 }
315 else
316 ++i;
317 }
318
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800319 if (!m_pendingInterestTable.empty()) {
320 m_pitTimeoutCheckTimerActive = true;
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800321
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800322 m_pitTimeoutCheckTimer->expires_from_now(boost::posix_time::milliseconds(100));
323 m_pitTimeoutCheckTimer->async_wait(bind(&Face::checkPitExpire, this));
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800324 }
325 else {
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800326 m_pitTimeoutCheckTimerActive = false;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800327
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800328 if (m_registeredPrefixTable.empty()) {
329 m_transport->close();
330 if (!m_ioServiceWork) {
331 m_processEventsTimeoutTimer->cancel();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800332 }
333 }
334 }
335}
336
337
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800338void
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800339Face::onReceiveElement(const Block& blockFromDaemon)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800340{
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800341 const Block& block = nfd::LocalControlHeader::getPayload(blockFromDaemon);
342
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800343 if (block.type() == Tlv::Interest)
344 {
345 shared_ptr<Interest> interest(new Interest());
346 interest->wireDecode(block);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800347 if (&block != &blockFromDaemon)
348 interest->getLocalControlHeader().wireDecode(blockFromDaemon);
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800349
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800350 RegisteredPrefixTable::iterator entry = getEntryForRegisteredPrefix(interest->getName());
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800351 if (entry != m_registeredPrefixTable.end()) {
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800352 (*entry)->getOnInterest()((*entry)->getPrefix(), *interest);
353 }
354 }
355 else if (block.type() == Tlv::Data)
356 {
357 shared_ptr<Data> data(new Data());
358 data->wireDecode(block);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800359 if (&block != &blockFromDaemon)
360 data->getLocalControlHeader().wireDecode(blockFromDaemon);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800361
362 PendingInterestTable::iterator entry = getEntryIndexForExpressedInterest(data->getName());
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800363 if (entry != m_pendingInterestTable.end()) {
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800364 // Copy pointers to the needed objects and remove the PIT entry before the calling the callback.
365 const OnData onData = (*entry)->getOnData();
366 const shared_ptr<const Interest> interest = (*entry)->getInterest();
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800367 m_pendingInterestTable.erase(entry);
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800368
369 if (onData) {
370 onData(*interest, *data);
371 }
372
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800373 if (m_pendingInterestTable.empty()) {
374 m_pitTimeoutCheckTimer->cancel(); // this will cause checkPitExpire invocation
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800375 }
376 }
377 }
Yingdi Yuf9fa52f2014-02-06 12:27:32 -0800378 // ignore any other type
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800379}
380
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800381Face::PendingInterestTable::iterator
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800382Face::getEntryIndexForExpressedInterest(const Name& name)
383{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800384 for (PendingInterestTable::iterator i = m_pendingInterestTable.begin ();
385 i != m_pendingInterestTable.end(); ++i)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800386 {
387 if ((*i)->getInterest()->matchesName(name))
388 {
389 return i;
390 }
391 }
392
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800393 return m_pendingInterestTable.end();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800394}
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800395
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800396Face::RegisteredPrefixTable::iterator
397Face::getEntryForRegisteredPrefix(const Name& name)
398{
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800399 RegisteredPrefixTable::iterator longestPrefix = m_registeredPrefixTable.end();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800400
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800401 for (RegisteredPrefixTable::iterator i = m_registeredPrefixTable.begin();
402 i != m_registeredPrefixTable.end();
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800403 ++i)
404 {
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800405 if ((*i)->getPrefix().isPrefixOf(name))
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800406 {
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800407
Alexander Afanasyevf39c5372014-02-17 19:42:56 -0800408 if (longestPrefix == m_registeredPrefixTable.end() ||
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800409 (*i)->getPrefix().size() > (*longestPrefix)->getPrefix().size())
410 {
411 longestPrefix = i;
412 }
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800413 }
414 }
415 return longestPrefix;
416}
417
418} // namespace ndn