blob: 3234f18a65d105400ea60151150cb74051fa0be9 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -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 Thompsonbf50a1a2013-08-20 18:01:01 -07005 * See COPYING for copyright and distribution information.
6 */
7
Jeff Thompsonea141d72013-09-19 14:40:10 -07008#include <stdexcept>
Jeff Thompson9ae4d782013-10-17 10:25:54 -07009#include "c/util/time.h"
Alexander Afanasyev96d914f2014-01-02 22:24:29 -080010
Jeff Thompson25b4e612013-10-10 16:03:24 -070011#include <ndn-cpp/forwarding-entry.hpp>
Alexander Afanasyev5d7db8e2014-01-05 22:43:57 -080012#include <ndn-cpp/face-instance.hpp>
Jeff Thompson25b4e612013-10-10 16:03:24 -070013#include <ndn-cpp/node.hpp>
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070014
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080015#include "util/ndnd-id-fetcher.hpp"
Alexander Afanasyev79100492014-01-03 15:35:38 -080016#include "security/signature/signature-sha256-with-rsa.hpp"
Alexander Afanasyev96d914f2014-01-02 22:24:29 -080017
Alexander Afanasyev18371872014-01-05 23:00:26 -080018#include "status-response.hpp"
19
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070020using namespace std;
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070021
22namespace ndn {
23
Jeff Thompson62992e42013-10-07 18:50:51 -070024uint64_t Node::PendingInterest::lastPendingInterestId_ = 0;
25uint64_t Node::RegisteredPrefix::lastRegisteredPrefixId_ = 0;
Jeff Thompson11095142013-10-01 16:20:28 -070026
Alexander Afanasyev0b688dc2013-12-18 16:43:37 -080027Node::Node(const ptr_lib::shared_ptr<Transport>& transport)
Alexander Afanasyeve1b7a5d2013-12-29 16:23:52 -080028 : transport_(transport)
29 , ndndIdFetcherInterest_(Name("/%C1.M.S.localhost/%C1.M.SRV/ndnd/KEY"), 4000.0)
30{
31 ioService_ = ptr_lib::make_shared<boost::asio::io_service>();
32 pitTimeoutCheckTimer_ = ptr_lib::make_shared<boost::asio::deadline_timer>(boost::ref(*ioService_));
33 processEventsTimeoutTimer_ = ptr_lib::make_shared<boost::asio::deadline_timer>(boost::ref(*ioService_));
34
35 pitTimeoutCheckTimer_->expires_from_now(boost::posix_time::milliseconds(100));
36 pitTimeoutCheckTimer_->async_wait(func_lib::bind(&Node::checkPitExpire, this));
37}
38
39Node::Node(const ptr_lib::shared_ptr<Transport>& transport, const ptr_lib::shared_ptr<boost::asio::io_service> &ioService)
40 : ioService_(ioService)
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080041 , transport_(transport)
42 , ndndIdFetcherInterest_(Name("/%C1.M.S.localhost/%C1.M.SRV/ndnd/KEY"), 4000.0)
Jeff Thompson557b81e2013-08-21 15:13:51 -070043{
Alexander Afanasyeve1b7a5d2013-12-29 16:23:52 -080044 pitTimeoutCheckTimer_ = ptr_lib::make_shared<boost::asio::deadline_timer>(boost::ref(*ioService_));
45 processEventsTimeoutTimer_ = ptr_lib::make_shared<boost::asio::deadline_timer>(boost::ref(*ioService_));
46
47 pitTimeoutCheckTimer_->expires_from_now(boost::posix_time::milliseconds(100));
48 pitTimeoutCheckTimer_->async_wait(func_lib::bind(&Node::checkPitExpire, this));
Jeff Thompson557b81e2013-08-21 15:13:51 -070049}
50
Jeff Thompson62992e42013-10-07 18:50:51 -070051uint64_t
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080052Node::expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout)
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070053{
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080054 if (!transport_->isConnected())
Alexander Afanasyeve1b7a5d2013-12-29 16:23:52 -080055 transport_->connect(*ioService_,
Alexander Afanasyev3ae2da22013-12-29 15:50:04 -080056 ptr_lib::bind(&Node::onReceiveElement, this, _1));
Jeff Thompson86507bc2013-08-23 20:51:38 -070057
Jeff Thompson62992e42013-10-07 18:50:51 -070058 uint64_t pendingInterestId = PendingInterest::getNextPendingInterestId();
Jeff Thompsonce115762013-12-18 14:59:56 -080059 pendingInterestTable_.push_back(ptr_lib::shared_ptr<PendingInterest>(new PendingInterest
60 (pendingInterestId, ptr_lib::shared_ptr<const Interest>(new Interest(interest)), onData, onTimeout)));
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080061
62 transport_->send(interest.wireEncode());
Jeff Thompson11095142013-10-01 16:20:28 -070063
64 return pendingInterestId;
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070065}
66
Jeff Thompson11095142013-10-01 16:20:28 -070067void
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -080068Node::put(const Data &data)
69{
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -080070 if (!transport_->isConnected())
Alexander Afanasyeve1b7a5d2013-12-29 16:23:52 -080071 transport_->connect(*ioService_,
Alexander Afanasyev3ae2da22013-12-29 15:50:04 -080072 ptr_lib::bind(&Node::onReceiveElement, this, _1));
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -080073
74 transport_->send(data.wireEncode());
75}
76
77
78void
Jeff Thompson62992e42013-10-07 18:50:51 -070079Node::removePendingInterest(uint64_t pendingInterestId)
Jeff Thompson11095142013-10-01 16:20:28 -070080{
81 // Go backwards through the list so we can erase entries.
82 // Remove all entries even though pendingInterestId should be unique.
83 for (int i = (int)pendingInterestTable_.size() - 1; i >= 0; --i) {
84 if (pendingInterestTable_[i]->getPendingInterestId() == pendingInterestId)
85 pendingInterestTable_.erase(pendingInterestTable_.begin() + i);
86 }
87}
88
Jeff Thompson62992e42013-10-07 18:50:51 -070089uint64_t
Jeff Thompson590ec232013-09-18 15:55:56 -070090Node::registerPrefix
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080091 (const Name& prefix, const OnInterest& onInterest, const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags)
Jeff Thompson86507bc2013-08-23 20:51:38 -070092{
Jeff Thompson11095142013-10-01 16:20:28 -070093 // Get the registeredPrefixId now so we can return it to the caller.
Jeff Thompson62992e42013-10-07 18:50:51 -070094 uint64_t registeredPrefixId = RegisteredPrefix::getNextRegisteredPrefixId();
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080095 ptr_lib::shared_ptr<const Name> prefixPtr = ptr_lib::make_shared<const Name>(prefix);
96
Jeff Thompson86507bc2013-08-23 20:51:38 -070097 if (ndndId_.size() == 0) {
98 // First fetch the ndndId of the connected hub.
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080099 NdndIdFetcher fetcher(ndndId_,
100 func_lib::bind(&Node::registerPrefixHelper, this,
101 registeredPrefixId, prefixPtr, onInterest, onRegisterFailed, flags),
102 func_lib::bind(onRegisterFailed, prefixPtr));
103
104 // @todo: Check if this crash
Jeff Thompsonce115762013-12-18 14:59:56 -0800105 // It is OK for func_lib::function make a copy of the function object because the Info is in a ptr_lib::shared_ptr.
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800106 expressInterest(ndndIdFetcherInterest_, fetcher, fetcher);
Jeff Thompson86507bc2013-08-23 20:51:38 -0700107 }
108 else
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800109 registerPrefixHelper(registeredPrefixId, prefixPtr, onInterest, onRegisterFailed, flags);
Jeff Thompson11095142013-10-01 16:20:28 -0700110
111 return registeredPrefixId;
112}
113
114void
Jeff Thompson62992e42013-10-07 18:50:51 -0700115Node::removeRegisteredPrefix(uint64_t registeredPrefixId)
Jeff Thompson11095142013-10-01 16:20:28 -0700116{
117 // Go backwards through the list so we can erase entries.
118 // Remove all entries even though pendingInterestId should be unique.
119 for (int i = (int)registeredPrefixTable_.size() - 1; i >= 0; --i) {
120 if (registeredPrefixTable_[i]->getRegisteredPrefixId() == registeredPrefixId)
121 registeredPrefixTable_.erase(registeredPrefixTable_.begin() + i);
122 }
Jeff Thompson86507bc2013-08-23 20:51:38 -0700123}
124
Jeff Thompson0050abe2013-09-17 12:50:25 -0700125void
Alexander Afanasyev79100492014-01-03 15:35:38 -0800126Node::registerPrefixHelper(uint64_t registeredPrefixId,
127 const ptr_lib::shared_ptr<const Name>& prefix,
128 const OnInterest& onInterest,
129 const OnRegisterFailed& onRegisterFailed,
130 const ForwardingFlags& flags)
Jeff Thompson86507bc2013-08-23 20:51:38 -0700131{
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700132 // Create a ForwardingEntry.
Alexander Afanasyevfbdfa092013-12-28 20:44:49 -0800133
134 // AlexA: ndnd ignores any freshness that is larger than 3600 sec and sets 300 sec instead
135 // to register "forever" (=2000000000 sec), freshnessPeriod must be omitted
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800136 ForwardingEntry forwardingEntry("selfreg", *prefix, -1, flags, -1);
137 Block content = forwardingEntry.wireEncode();
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700138
139 // Set the ForwardingEntry as the content of a Data packet and sign.
140 Data data;
Jeff Thompsonc2b7b142013-09-12 15:29:04 -0700141 data.setContent(content);
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700142
Alexander Afanasyev79100492014-01-03 15:35:38 -0800143 // Create an empty signature, since nobody going to verify it for now
144 // @todo In the future, we may require real signatures to do the registration
145 SignatureSha256WithRsa signature;
146 signature.setValue(Block(Tlv::SignatureValue, ptr_lib::make_shared<Buffer>()));
147 data.setSignature(signature);
148
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700149 // Create an interest where the name has the encoded Data packet.
150 Name interestName;
Alexander Afanasyev18371872014-01-05 23:00:26 -0800151 interestName.append("ndnx");
Jeff Thompson3a715632013-10-31 11:36:35 -0700152 interestName.append(ndndId_);
Alexander Afanasyev18371872014-01-05 23:00:26 -0800153 interestName.append("selfreg");
Alexander Afanasyev79100492014-01-03 15:35:38 -0800154 interestName.append(data.wireEncode());
Alexander Afanasyev18371872014-01-05 23:00:26 -0800155
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700156 Interest interest(interestName);
157 interest.setScope(1);
Alexander Afanasyev18371872014-01-05 23:00:26 -0800158 interest.setInterestLifetime(1000);
159
160 expressInterest(interest,
161 func_lib::bind(&Node::registerPrefixFinal, this,
162 registeredPrefixId, prefix, onInterest, onRegisterFailed, _1, _2),
163 func_lib::bind(onRegisterFailed, prefix));
164}
165
166void
167Node::registerPrefixFinal(uint64_t registeredPrefixId,
168 const ptr_lib::shared_ptr<const Name>& prefix,
169 const OnInterest& onInterest,
170 const OnRegisterFailed& onRegisterFailed,
171 const ptr_lib::shared_ptr<const Interest>&, const ptr_lib::shared_ptr<Data>&data)
172{
173 Block content = data->getContent();
174 content.parse();
175
176 if (content.getAll().empty())
177 {
178 onRegisterFailed(prefix);
179 return;
180 }
181
Alexander Afanasyeve0c02f52013-12-28 20:44:25 -0800182 Block::element_iterator val = content.getAll().begin();
183
184 switch(val->type())
Alexander Afanasyev18371872014-01-05 23:00:26 -0800185 {
186 case Tlv::FaceManagement::ForwardingEntry:
187 {
Alexander Afanasyeve0c02f52013-12-28 20:44:25 -0800188 ForwardingEntry entry;
189 entry.wireDecode(*val);
190
191 // Save the onInterest callback and send the registration interest.
192 registeredPrefixTable_.push_back(ptr_lib::make_shared<RegisteredPrefix>(registeredPrefixId, prefix, onInterest));
193
194 /// @todo Notify user about successful registration
195
Alexander Afanasyev18371872014-01-05 23:00:26 -0800196 // succeeded
Alexander Afanasyeve0c02f52013-12-28 20:44:25 -0800197 return;
Alexander Afanasyev18371872014-01-05 23:00:26 -0800198 }
199 case Tlv::FaceManagement::StatusResponse:
200 {
201 // failed :(
202 StatusResponse resp;
Alexander Afanasyeve0c02f52013-12-28 20:44:25 -0800203 resp.wireDecode(*val);
Alexander Afanasyev18371872014-01-05 23:00:26 -0800204
205 std::cerr << "StatusReponse: " << resp << std::endl;
206
207 onRegisterFailed(prefix);
208 return;
Alexander Afanasyev18371872014-01-05 23:00:26 -0800209 }
210 default:
211 {
212 // failed :(
213
214 onRegisterFailed(prefix);
215 return;
Alexander Afanasyev18371872014-01-05 23:00:26 -0800216 }
217 }
Jeff Thompson86507bc2013-08-23 20:51:38 -0700218}
219
Jeff Thompson0050abe2013-09-17 12:50:25 -0700220void
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800221Node::processEvents(Milliseconds timeout/* = 0 */)
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -0700222{
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800223 if (timeout > 0)
224 {
Alexander Afanasyeve1b7a5d2013-12-29 16:23:52 -0800225 processEventsTimeoutTimer_->expires_from_now(boost::posix_time::milliseconds(timeout));
226 processEventsTimeoutTimer_->async_wait(fireProcessEventsTimeout);
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800227 }
228 try
229 {
Alexander Afanasyeve1b7a5d2013-12-29 16:23:52 -0800230 ioService_->run();
231 ioService_->reset();
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800232 }
Alexander Afanasyev3ae2da22013-12-29 15:50:04 -0800233 catch(Node::ProcessEventsTimeout &)
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800234 {
Alexander Afanasyev3ae2da22013-12-29 15:50:04 -0800235 // break
Alexander Afanasyeva557d5a2013-12-28 21:59:03 -0800236 }
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800237}
238
239void
Alexander Afanasyev3ae2da22013-12-29 15:50:04 -0800240Node::fireProcessEventsTimeout(const boost::system::error_code& error)
241{
242 if (!error) // can fire for some other reason, e.g., cancelled
243 throw Node::ProcessEventsTimeout();
244}
245
246void
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800247Node::checkPitExpire()
248{
Jeff Thompson48917f02013-08-21 17:12:45 -0700249 // Check for PIT entry timeouts. Go backwards through the list so we can erase entries.
Jeff Thompson9a8e82f2013-10-17 14:13:43 -0700250 MillisecondsSince1970 nowMilliseconds = ndn_getNowMilliseconds();
Jeff Thompson11095142013-10-01 16:20:28 -0700251 for (int i = (int)pendingInterestTable_.size() - 1; i >= 0; --i) {
Jeff Thompson3b0ed532013-11-05 13:43:40 -0800252 if (pendingInterestTable_[i]->isTimedOut(nowMilliseconds)) {
253 // Save the PendingInterest and remove it from the PIT. Then call the callback.
Jeff Thompsonce115762013-12-18 14:59:56 -0800254 ptr_lib::shared_ptr<PendingInterest> pendingInterest = pendingInterestTable_[i];
Jeff Thompson11095142013-10-01 16:20:28 -0700255 pendingInterestTable_.erase(pendingInterestTable_.begin() + i);
Jeff Thompson3b0ed532013-11-05 13:43:40 -0800256 pendingInterest->callTimeout();
Jeff Thompson48917f02013-08-21 17:12:45 -0700257
258 // Refresh now since the timeout callback might have delayed.
Jeff Thompson9ae4d782013-10-17 10:25:54 -0700259 nowMilliseconds = ndn_getNowMilliseconds();
Jeff Thompson48917f02013-08-21 17:12:45 -0700260 }
261 }
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800262
Alexander Afanasyeve1b7a5d2013-12-29 16:23:52 -0800263 pitTimeoutCheckTimer_->expires_from_now(boost::posix_time::milliseconds(100));
264 pitTimeoutCheckTimer_->async_wait(func_lib::bind(&Node::checkPitExpire, this));
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -0700265}
266
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800267
Jeff Thompson0050abe2013-09-17 12:50:25 -0700268void
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800269Node::onReceiveElement(const Block &block)
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -0700270{
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800271 if (block.type() == Tlv::Interest)
Alexander Afanasyev96d914f2014-01-02 22:24:29 -0800272 {
273 ptr_lib::shared_ptr<Interest> interest(new Interest());
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800274 interest->wireDecode(block);
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700275
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800276 RegisteredPrefixTable::iterator entry = getEntryForRegisteredPrefix(interest->getName());
277 if (entry != registeredPrefixTable_.end()) {
278 (*entry)->getOnInterest()((*entry)->getPrefix(), interest, *transport_, (*entry)->getRegisteredPrefixId());
279 }
Jeff Thompson557b81e2013-08-21 15:13:51 -0700280 }
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800281 else if (block.type() == Tlv::Data)
Alexander Afanasyev96d914f2014-01-02 22:24:29 -0800282 {
283 ptr_lib::shared_ptr<Data> data(new Data());
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800284 data->wireDecode(block);
285
286 PendingInterestTable::iterator entry = getEntryIndexForExpressedInterest(data->getName());
287 if (entry != pendingInterestTable_.end()) {
Alexander Afanasyev96d914f2014-01-02 22:24:29 -0800288 // Copy pointers to the needed objects and remove the PIT entry before the calling the callback.
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800289 const OnData onData = (*entry)->getOnData();
290 const ptr_lib::shared_ptr<const Interest> interest = (*entry)->getInterest();
291 pendingInterestTable_.erase(entry);
Alexander Afanasyev96d914f2014-01-02 22:24:29 -0800292 onData(interest, data);
293 }
294 }
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -0700295}
296
Jeff Thompson0050abe2013-09-17 12:50:25 -0700297void
298Node::shutdown()
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -0700299{
300 transport_->close();
Alexander Afanasyeve1b7a5d2013-12-29 16:23:52 -0800301 ioService_->stop();
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -0700302}
303
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800304Node::PendingInterestTable::iterator
Jeff Thompson0050abe2013-09-17 12:50:25 -0700305Node::getEntryIndexForExpressedInterest(const Name& name)
Jeff Thompson557b81e2013-08-21 15:13:51 -0700306{
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800307 for (PendingInterestTable::iterator i = pendingInterestTable_.begin ();
308 i != pendingInterestTable_.end(); ++i)
309 {
310 if ((*i)->getInterest()->matchesName(name))
311 {
312 return i;
313 }
Jeff Thompson557b81e2013-08-21 15:13:51 -0700314 }
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800315
316 return pendingInterestTable_.end();
Jeff Thompson557b81e2013-08-21 15:13:51 -0700317}
Jeff Thompson86507bc2013-08-23 20:51:38 -0700318
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800319Node::RegisteredPrefixTable::iterator
Jeff Thompson0050abe2013-09-17 12:50:25 -0700320Node::getEntryForRegisteredPrefix(const Name& name)
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700321{
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800322 RegisteredPrefixTable::iterator longestPrefix = registeredPrefixTable_.end();
323
324 for (RegisteredPrefixTable::iterator i = registeredPrefixTable_.begin();
325 i != registeredPrefixTable_.end();
326 ++i)
327 {
328 if (longestPrefix == registeredPrefixTable_.end() ||
329 (*i)->getPrefix()->size() > (*longestPrefix)->getPrefix()->size())
330 {
331 longestPrefix = i;
332 }
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700333 }
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800334 return longestPrefix;
Jeff Thompson9cc4be42013-08-27 18:12:41 -0700335}
336
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800337Node::PendingInterest::PendingInterest(uint64_t pendingInterestId,
338 const ptr_lib::shared_ptr<const Interest>& interest,
339 const OnData& onData, const OnTimeout& onTimeout)
340: pendingInterestId_(pendingInterestId),
341 interest_(interest),
342 onData_(onData), onTimeout_(onTimeout)
Jeff Thompson86507bc2013-08-23 20:51:38 -0700343{
344 // Set up timeoutTime_.
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -0800345 if (interest_->getInterestLifetime() >= 0)
346 timeoutTimeMilliseconds_ = ndn_getNowMilliseconds() + interest_->getInterestLifetime();
Jeff Thompson86507bc2013-08-23 20:51:38 -0700347 else
348 // No timeout.
Alexander Afanasyevb24a68a2013-12-28 16:53:21 -0800349 /**
350 * @todo Set more meaningful default timeout. This timeout MUST exist.
351 */
352 timeoutTimeMilliseconds_ = ndn_getNowMilliseconds() + 4000;
Jeff Thompson86507bc2013-08-23 20:51:38 -0700353}
354
Jeff Thompson3b0ed532013-11-05 13:43:40 -0800355void
356Node::PendingInterest::callTimeout()
Jeff Thompson86507bc2013-08-23 20:51:38 -0700357{
Jeff Thompson3b0ed532013-11-05 13:43:40 -0800358 if (onTimeout_) {
359 // Ignore all exceptions.
360 try {
361 onTimeout_(interest_);
Jeff Thompson86507bc2013-08-23 20:51:38 -0700362 }
Jeff Thompson3b0ed532013-11-05 13:43:40 -0800363 catch (...) { }
Jeff Thompson86507bc2013-08-23 20:51:38 -0700364 }
Jeff Thompson86507bc2013-08-23 20:51:38 -0700365}
Jeff Thompson557b81e2013-08-21 15:13:51 -0700366
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -0700367}