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 | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 8 | #include "common.hpp" |
| 9 | |
Alexander Afanasyev | e9fdb80 | 2014-02-05 17:36:51 -0800 | [diff] [blame] | 10 | #include "node.hpp" |
Alexander Afanasyev | 96d914f | 2014-01-02 22:24:29 -0800 | [diff] [blame] | 11 | |
Alexander Afanasyev | e9fdb80 | 2014-02-05 17:36:51 -0800 | [diff] [blame] | 12 | #include "security/signature-sha256-with-rsa.hpp" |
| 13 | |
| 14 | #include "util/time.hpp" |
| 15 | #include "util/random.hpp" |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 16 | |
| 17 | namespace ndn { |
| 18 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 19 | Node::Node(const shared_ptr<Transport>& transport) |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 20 | : pitTimeoutCheckTimerActive_(false) |
| 21 | , transport_(transport) |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 22 | , m_fwController(*this) |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 23 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 24 | ioService_ = make_shared<boost::asio::io_service>(); |
| 25 | pitTimeoutCheckTimer_ = make_shared<boost::asio::deadline_timer>(boost::ref(*ioService_)); |
| 26 | processEventsTimeoutTimer_ = make_shared<boost::asio::deadline_timer>(boost::ref(*ioService_)); |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 27 | } |
| 28 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 29 | Node::Node(const shared_ptr<Transport>& transport, const shared_ptr<boost::asio::io_service> &ioService) |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 30 | : ioService_(ioService) |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 31 | , pitTimeoutCheckTimerActive_(false) |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 32 | , transport_(transport) |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 33 | , m_fwController(*this) |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 34 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 35 | pitTimeoutCheckTimer_ = make_shared<boost::asio::deadline_timer>(boost::ref(*ioService_)); |
| 36 | processEventsTimeoutTimer_ = make_shared<boost::asio::deadline_timer>(boost::ref(*ioService_)); |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 39 | const PendingInterestId* |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 40 | Node::expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout) |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 41 | { |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 42 | if (!transport_->isConnected()) |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 43 | transport_->connect(*ioService_, |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 44 | bind(&Node::onReceiveElement, this, _1)); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 46 | shared_ptr<const Interest> interestToExpress(new Interest(interest)); |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 47 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 48 | ioService_->post(bind(&Node::asyncExpressInterest, this, interestToExpress, onData, onTimeout)); |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 49 | |
| 50 | return reinterpret_cast<const PendingInterestId*>(interestToExpress.get()); |
| 51 | } |
| 52 | |
| 53 | void |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 54 | Node::asyncExpressInterest(const shared_ptr<const Interest> &interest, |
| 55 | const OnData& onData, const OnTimeout& onTimeout) |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 56 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 57 | pendingInterestTable_.push_back(shared_ptr<PendingInterest>(new PendingInterest |
| 58 | (interest, onData, onTimeout))); |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 59 | |
| 60 | transport_->send(interest->wireEncode()); |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 61 | |
| 62 | if (!pitTimeoutCheckTimerActive_) { |
| 63 | pitTimeoutCheckTimerActive_ = true; |
| 64 | pitTimeoutCheckTimer_->expires_from_now(boost::posix_time::milliseconds(100)); |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 65 | pitTimeoutCheckTimer_->async_wait(bind(&Node::checkPitExpire, this)); |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 66 | } |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 67 | } |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 68 | |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 69 | void |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 70 | Node::put(const Data &data) |
| 71 | { |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 72 | if (!transport_->isConnected()) |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 73 | transport_->connect(*ioService_, |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 74 | bind(&Node::onReceiveElement, this, _1)); |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 75 | |
| 76 | transport_->send(data.wireEncode()); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 81 | Node::removePendingInterest(const PendingInterestId *pendingInterestId) |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 82 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 83 | ioService_->post(bind(&Node::asyncRemovePendingInterest, this, pendingInterestId)); |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 86 | |
| 87 | void |
| 88 | Node::asyncRemovePendingInterest(const PendingInterestId *pendingInterestId) |
| 89 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 90 | pendingInterestTable_.remove_if(MatchPendingInterestId(pendingInterestId)); |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | const RegisteredPrefixId* |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 94 | Node::setInterestFilter(const Name& prefix, |
| 95 | const OnInterest& onInterest, |
| 96 | const OnSetInterestFilterFailed& onSetInterestFilterFailed) |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 97 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 98 | shared_ptr<RegisteredPrefix> prefixToRegister(new RegisteredPrefix(prefix, onInterest)); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 100 | m_fwController.selfRegisterPrefix(prefixToRegister->getPrefix(), |
| 101 | bind(&RegisteredPrefixTable::push_back, ®isteredPrefixTable_, prefixToRegister), |
| 102 | bind(onSetInterestFilterFailed, prefixToRegister->getPrefix().shared_from_this())); |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 104 | return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get()); |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 108 | Node::unsetInterestFilter(const RegisteredPrefixId *registeredPrefixId) |
| 109 | { |
| 110 | ioService_->post(bind(&Node::asyncUnsetInterestFilter, this, registeredPrefixId)); |
| 111 | } |
| 112 | |
| 113 | void |
| 114 | Node::asyncUnsetInterestFilter(const RegisteredPrefixId *registeredPrefixId) |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 115 | { |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 116 | RegisteredPrefixTable::iterator i = std::find_if(registeredPrefixTable_.begin(), registeredPrefixTable_.end(), |
| 117 | MatchRegisteredPrefixId(registeredPrefixId)); |
| 118 | if (i != registeredPrefixTable_.end()) |
Alexander Afanasyev | bc343ef | 2014-01-09 22:36:20 -0800 | [diff] [blame] | 119 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 120 | m_fwController.selfDeregisterPrefix((*i)->getPrefix(), |
| 121 | bind(&RegisteredPrefixTable::erase, ®isteredPrefixTable_, i), |
| 122 | ndnd::Control::FailCallback()); |
Alexander Afanasyev | bc343ef | 2014-01-09 22:36:20 -0800 | [diff] [blame] | 123 | } |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 124 | |
| 125 | // there cannot be two registered prefixes with the same id. if there are, then something is broken |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 128 | void |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 129 | Node::processEvents(Milliseconds timeout/* = 0 */, bool keepThread/* = false*/) |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 130 | { |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 131 | try |
| 132 | { |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 133 | if (timeout < 0) |
| 134 | { |
| 135 | // do not block if timeout is negative, but process pending events |
| 136 | ioService_->poll(); |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | if (timeout > 0) |
| 141 | { |
| 142 | processEventsTimeoutTimer_->expires_from_now(boost::posix_time::milliseconds(timeout)); |
Jeff Thompson | 6e9fc18 | 2014-01-23 13:04:08 -0800 | [diff] [blame] | 143 | processEventsTimeoutTimer_->async_wait(&fireProcessEventsTimeout); |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | if (keepThread) { |
| 147 | // work will ensure that ioService_ is running until work object exists |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 148 | ioServiceWork_ = make_shared<boost::asio::io_service::work>(boost::ref(*ioService_)); |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 151 | ioService_->run(); |
Alexander Afanasyev | 8995f54 | 2014-01-17 15:33:44 -0800 | [diff] [blame] | 152 | ioService_->reset(); // so it is possible to run processEvents again (if necessary) |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 153 | } |
Alexander Afanasyev | 3ae2da2 | 2013-12-29 15:50:04 -0800 | [diff] [blame] | 154 | catch(Node::ProcessEventsTimeout &) |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 155 | { |
Alexander Afanasyev | 3ae2da2 | 2013-12-29 15:50:04 -0800 | [diff] [blame] | 156 | // break |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 157 | ioService_->reset(); |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 158 | } |
Alexander Afanasyev | 8995f54 | 2014-01-17 15:33:44 -0800 | [diff] [blame] | 159 | catch(const std::exception &) |
| 160 | { |
| 161 | ioService_->reset(); |
| 162 | pendingInterestTable_.clear(); |
| 163 | registeredPrefixTable_.clear(); |
| 164 | throw; |
| 165 | } |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 168 | void |
| 169 | Node::shutdown() |
| 170 | { |
| 171 | pendingInterestTable_.clear(); |
| 172 | registeredPrefixTable_.clear(); |
| 173 | |
| 174 | transport_->close(); |
| 175 | pitTimeoutCheckTimer_->cancel(); |
| 176 | processEventsTimeoutTimer_->cancel(); |
| 177 | pitTimeoutCheckTimerActive_ = false; |
| 178 | } |
| 179 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 180 | void |
Alexander Afanasyev | 3ae2da2 | 2013-12-29 15:50:04 -0800 | [diff] [blame] | 181 | Node::fireProcessEventsTimeout(const boost::system::error_code& error) |
| 182 | { |
| 183 | if (!error) // can fire for some other reason, e.g., cancelled |
| 184 | throw Node::ProcessEventsTimeout(); |
| 185 | } |
| 186 | |
| 187 | void |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 188 | Node::checkPitExpire() |
| 189 | { |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 190 | // Check for PIT entry timeouts. Go backwards through the list so we can erase entries. |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 191 | MillisecondsSince1970 nowMilliseconds = getNowMilliseconds(); |
| 192 | |
| 193 | PendingInterestTable::iterator i = pendingInterestTable_.begin(); |
| 194 | while (i != pendingInterestTable_.end()) |
| 195 | { |
| 196 | if ((*i)->isTimedOut(nowMilliseconds)) |
| 197 | { |
| 198 | // Save the PendingInterest and remove it from the PIT. Then call the callback. |
| 199 | shared_ptr<PendingInterest> pendingInterest = *i; |
| 200 | |
| 201 | i = pendingInterestTable_.erase(i); |
| 202 | |
| 203 | pendingInterest->callTimeout(); |
| 204 | } |
| 205 | else |
| 206 | ++i; |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 207 | } |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 208 | |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 209 | if (!pendingInterestTable_.empty()) { |
Alexander Afanasyev | bc343ef | 2014-01-09 22:36:20 -0800 | [diff] [blame] | 210 | pitTimeoutCheckTimerActive_ = true; |
| 211 | |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 212 | pitTimeoutCheckTimer_->expires_from_now(boost::posix_time::milliseconds(100)); |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 213 | pitTimeoutCheckTimer_->async_wait(bind(&Node::checkPitExpire, this)); |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 214 | } |
| 215 | else { |
| 216 | pitTimeoutCheckTimerActive_ = false; |
| 217 | |
| 218 | if (registeredPrefixTable_.empty()) { |
| 219 | transport_->close(); |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 220 | if (!ioServiceWork_) { |
| 221 | processEventsTimeoutTimer_->cancel(); |
| 222 | } |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 223 | } |
| 224 | } |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 227 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 228 | void |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 229 | Node::onReceiveElement(const Block &block) |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 230 | { |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 231 | if (block.type() == Tlv::Interest) |
Alexander Afanasyev | 96d914f | 2014-01-02 22:24:29 -0800 | [diff] [blame] | 232 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 233 | shared_ptr<Interest> interest(new Interest()); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 234 | interest->wireDecode(block); |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 235 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 236 | RegisteredPrefixTable::iterator entry = getEntryForRegisteredPrefix(interest->getName()); |
| 237 | if (entry != registeredPrefixTable_.end()) { |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 238 | (*entry)->getOnInterest()((*entry)->getPrefix().shared_from_this(), interest); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 239 | } |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 240 | } |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 241 | else if (block.type() == Tlv::Data) |
Alexander Afanasyev | 96d914f | 2014-01-02 22:24:29 -0800 | [diff] [blame] | 242 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 243 | shared_ptr<Data> data(new Data()); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 244 | data->wireDecode(block); |
| 245 | |
| 246 | PendingInterestTable::iterator entry = getEntryIndexForExpressedInterest(data->getName()); |
| 247 | if (entry != pendingInterestTable_.end()) { |
Alexander Afanasyev | 96d914f | 2014-01-02 22:24:29 -0800 | [diff] [blame] | 248 | // Copy pointers to the needed objects and remove the PIT entry before the calling the callback. |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 249 | const OnData onData = (*entry)->getOnData(); |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 250 | const shared_ptr<const Interest> interest = (*entry)->getInterest(); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 251 | pendingInterestTable_.erase(entry); |
Alexander Afanasyev | bc343ef | 2014-01-09 22:36:20 -0800 | [diff] [blame] | 252 | |
| 253 | if (onData) { |
| 254 | onData(interest, data); |
| 255 | } |
| 256 | |
| 257 | if (pendingInterestTable_.empty()) { |
| 258 | pitTimeoutCheckTimer_->cancel(); // this will cause checkPitExpire invocation |
| 259 | } |
Alexander Afanasyev | 96d914f | 2014-01-02 22:24:29 -0800 | [diff] [blame] | 260 | } |
| 261 | } |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 264 | Node::PendingInterestTable::iterator |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 265 | Node::getEntryIndexForExpressedInterest(const Name& name) |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 266 | { |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 267 | for (PendingInterestTable::iterator i = pendingInterestTable_.begin (); |
| 268 | i != pendingInterestTable_.end(); ++i) |
| 269 | { |
| 270 | if ((*i)->getInterest()->matchesName(name)) |
| 271 | { |
| 272 | return i; |
| 273 | } |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 274 | } |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 275 | |
| 276 | return pendingInterestTable_.end(); |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 277 | } |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 278 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 279 | Node::RegisteredPrefixTable::iterator |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 280 | Node::getEntryForRegisteredPrefix(const Name& name) |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 281 | { |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 282 | RegisteredPrefixTable::iterator longestPrefix = registeredPrefixTable_.end(); |
| 283 | |
| 284 | for (RegisteredPrefixTable::iterator i = registeredPrefixTable_.begin(); |
| 285 | i != registeredPrefixTable_.end(); |
| 286 | ++i) |
| 287 | { |
| 288 | if (longestPrefix == registeredPrefixTable_.end() || |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 289 | (*i)->getPrefix().size() > (*longestPrefix)->getPrefix().size()) |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 290 | { |
| 291 | longestPrefix = i; |
| 292 | } |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 293 | } |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 294 | return longestPrefix; |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 297 | } // namespace ndn |