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 | |
| 8 | #ifndef NDN_NODE_HPP |
| 9 | #define NDN_NODE_HPP |
| 10 | |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 11 | #include "common.hpp" |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 12 | #include "interest.hpp" |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 13 | #include "data.hpp" |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 14 | #include "forwarding-flags.hpp" |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 15 | #include "transport/transport.hpp" |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 16 | |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 17 | namespace ndn { |
| 18 | |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 19 | struct PendingInterestId; |
| 20 | struct RegisteredPrefixId; |
| 21 | |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 22 | /** |
| 23 | * An OnData function object is used to pass a callback to expressInterest. |
| 24 | */ |
Jeff Thompson | a6d15c8 | 2013-09-17 15:34:32 -0700 | [diff] [blame] | 25 | typedef func_lib::function<void(const ptr_lib::shared_ptr<const Interest>&, const ptr_lib::shared_ptr<Data>&)> OnData; |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * An OnTimeout function object is used to pass a callback to expressInterest. |
| 29 | */ |
Jeff Thompson | a6d15c8 | 2013-09-17 15:34:32 -0700 | [diff] [blame] | 30 | typedef func_lib::function<void(const ptr_lib::shared_ptr<const Interest>&)> OnTimeout; |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 31 | |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 32 | /** |
| 33 | * An OnInterest function object is used to pass a callback to registerPrefix. |
| 34 | */ |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 35 | typedef func_lib::function<void |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 36 | (const ptr_lib::shared_ptr<const Name>&, const ptr_lib::shared_ptr<const Interest>&)> OnInterest; |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 37 | |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 38 | /** |
| 39 | * An OnRegisterFailed function object is used to report when registerPrefix fails. |
| 40 | */ |
| 41 | typedef func_lib::function<void(const ptr_lib::shared_ptr<const Name>&)> OnRegisterFailed; |
| 42 | |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 43 | class Face; |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 45 | class Node { |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 46 | public: |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 47 | struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| 48 | |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 49 | /** |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 50 | * Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo. |
| 51 | * @param transport A shared_ptr to a Transport object used for communication. |
| 52 | * @param transport A shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport. |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 53 | */ |
Alexander Afanasyev | 0b688dc | 2013-12-18 16:43:37 -0800 | [diff] [blame] | 54 | Node(const ptr_lib::shared_ptr<Transport>& transport); |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * @brief Alternative (special use case) version of the constructor, can be used to aggregate |
| 58 | * several Faces within one processing thread |
| 59 | * |
| 60 | * <code> |
| 61 | * Face face1(...); |
| 62 | * Face face2(..., face1.getAsyncService()); |
| 63 | * |
| 64 | * // Now the following ensures that events on both faces are processed |
| 65 | * face1.processEvents(); |
| 66 | * </code> |
| 67 | */ |
| 68 | Node(const ptr_lib::shared_ptr<Transport>& transport, const ptr_lib::shared_ptr<boost::asio::io_service> &ioService); |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 71 | * Send the Interest through the transport, read the entire response and call onData(interest, data). |
| 72 | * @param interest A reference to the Interest. This copies the Interest. |
| 73 | * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to |
| 74 | * use func_lib::ref() as appropriate. |
| 75 | * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it. |
| 76 | * This copies the function object, so you may need to use func_lib::ref() as appropriate. |
Jeff Thompson | 978c152 | 2013-11-12 23:03:10 -0800 | [diff] [blame] | 77 | * @param wireFormat A WireFormat object used to encode the message. |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 78 | * @return The pending interest ID which can be used with removePendingInterest. |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 79 | */ |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 80 | const PendingInterestId* |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 81 | expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout); |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 84 | * Remove the pending interest entry with the pendingInterestId from the pending interest table. |
| 85 | * This does not affect another pending interest with a different pendingInterestId, even it if has the same interest name. |
| 86 | * If there is no entry with the pendingInterestId, do nothing. |
| 87 | * @param pendingInterestId The ID returned from expressInterest. |
| 88 | */ |
| 89 | void |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 90 | removePendingInterest(const PendingInterestId *pendingInterestId); |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 93 | * Register prefix with the connected NDN hub and call onInterest when a matching interest is received. |
| 94 | * @param prefix A reference to a Name for the prefix to register. This copies the Name. |
| 95 | * @param onInterest A function object to call when a matching interest is received. This copies the function object, so you may need to |
| 96 | * use func_lib::ref() as appropriate. |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 97 | * @param onRegisterFailed A function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. |
| 98 | * This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix. |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 99 | * @param flags The flags for finer control of which interests are forward to the application. |
Jeff Thompson | 978c152 | 2013-11-12 23:03:10 -0800 | [diff] [blame] | 100 | * @param wireFormat A WireFormat object used to encode the message. |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 101 | * @return The registered prefix ID which can be used with removeRegisteredPrefix. |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 102 | */ |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 103 | const RegisteredPrefixId* |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 104 | registerPrefix |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 105 | (const Name& prefix, const OnInterest& onInterest, const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags); |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 108 | * Remove the registered prefix entry with the registeredPrefixId from the pending interest table. |
| 109 | * This does not affect another registered prefix with a different registeredPrefixId, even it if has the same prefix name. |
| 110 | * If there is no entry with the registeredPrefixId, do nothing. |
| 111 | * @param registeredPrefixId The ID returned from registerPrefix. |
| 112 | */ |
| 113 | void |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 114 | removeRegisteredPrefix(const RegisteredPrefixId *registeredPrefixId); |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 115 | |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 116 | /** |
| 117 | * @brief Publish data packet |
| 118 | * |
| 119 | * This method can be called to satisfy the incoming Interest or to put Data packet into the cache |
| 120 | * of the local NDN forwarder |
| 121 | */ |
| 122 | void |
| 123 | put(const Data &data); |
| 124 | |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 125 | /** |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 126 | * Process any data to receive or call timeout callbacks. |
| 127 | * |
| 128 | * This call will block forever (default timeout == 0) to process IO on the face. |
| 129 | * To exit, one expected to call face.shutdown() from one of the callback methods. |
| 130 | * |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 131 | * If positive timeout is specified, then processEvents will exit after this timeout, |
| 132 | * if not stopped earlier with face.shutdown() or when all active events finish. |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 133 | * The call can be called repeatedly, if desired. |
| 134 | * |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 135 | * If negative timeout is specified, then processEvents will not block and process only pending |
| 136 | * events. |
| 137 | * |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 138 | * @throw This may throw an exception for reading data or in the callback for processing the data. If you |
| 139 | * call this from an main event loop, you may want to catch and log/disregard all exceptions. |
| 140 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 141 | void |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 142 | processEvents(Milliseconds timeout = 0, bool keepThread = false); |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 143 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 144 | const ptr_lib::shared_ptr<Transport>& |
| 145 | getTransport() { return transport_; } |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 146 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 147 | void |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 148 | shutdown(); |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 149 | |
| 150 | private: |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 151 | void |
| 152 | asyncExpressInterest(const ptr_lib::shared_ptr<const Interest> &interest, |
| 153 | const OnData& onData, const OnTimeout& onTimeout); |
| 154 | |
| 155 | void |
| 156 | asyncRemovePendingInterest(const PendingInterestId *pendingInterestId); |
| 157 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 158 | void |
| 159 | onReceiveElement(const Block &wire); |
| 160 | |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 161 | struct ProcessEventsTimeout {}; |
Alexander Afanasyev | 3ae2da2 | 2013-12-29 15:50:04 -0800 | [diff] [blame] | 162 | static void |
| 163 | fireProcessEventsTimeout(const boost::system::error_code& error); |
| 164 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 165 | private: |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 166 | class PendingInterest { |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 167 | public: |
| 168 | /** |
| 169 | * Create a new PitEntry and set the timeoutTime_ based on the current time and the interest lifetime. |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 170 | * @param interest A shared_ptr for the interest. |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 171 | * @param onData A function object to call when a matching data packet is received. |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 172 | * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it. |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 173 | */ |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 174 | PendingInterest |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 175 | (const ptr_lib::shared_ptr<const Interest>& interest, const OnData& onData, |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 176 | const OnTimeout& onTimeout); |
| 177 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 178 | const ptr_lib::shared_ptr<const Interest>& |
| 179 | getInterest() { return interest_; } |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 180 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 181 | const OnData& |
| 182 | getOnData() { return onData_; } |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 183 | |
| 184 | /** |
Jeff Thompson | 3b0ed53 | 2013-11-05 13:43:40 -0800 | [diff] [blame] | 185 | * Check if this interest is timed out. |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 186 | * @param nowMilliseconds The current time in milliseconds from ndn_getNowMilliseconds. |
Jeff Thompson | 3b0ed53 | 2013-11-05 13:43:40 -0800 | [diff] [blame] | 187 | * @return true if this interest timed out, otherwise false. |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 188 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 189 | bool |
Jeff Thompson | 3b0ed53 | 2013-11-05 13:43:40 -0800 | [diff] [blame] | 190 | isTimedOut(MillisecondsSince1970 nowMilliseconds) |
| 191 | { |
| 192 | return timeoutTimeMilliseconds_ >= 0.0 && nowMilliseconds >= timeoutTimeMilliseconds_; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Call onTimeout_ (if defined). This ignores exceptions from the onTimeout_. |
| 197 | */ |
| 198 | void |
| 199 | callTimeout(); |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 200 | |
| 201 | private: |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 202 | ptr_lib::shared_ptr<const Interest> interest_; |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 203 | const OnData onData_; |
| 204 | const OnTimeout onTimeout_; |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 205 | |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 206 | MillisecondsSince1970 timeoutTimeMilliseconds_; /**< The time when the interest times out in milliseconds according to ndn_getNowMilliseconds, or -1 for no timeout. */ |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 207 | }; |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 208 | |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 209 | // Functor to match pending interests against PendingInterestId |
| 210 | struct MatchPendingInterestId |
| 211 | { |
| 212 | MatchPendingInterestId(const PendingInterestId *pendingInterestId) |
| 213 | : id_(pendingInterestId) |
| 214 | { |
| 215 | } |
| 216 | |
| 217 | bool |
| 218 | operator()(const ptr_lib::shared_ptr<const PendingInterest> &pendingInterest) const |
| 219 | { |
| 220 | return (reinterpret_cast<const PendingInterestId *>(pendingInterest.get()) == id_); |
| 221 | } |
| 222 | private: |
| 223 | const PendingInterestId *id_; |
| 224 | }; |
| 225 | |
| 226 | |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 227 | class RegisteredPrefix { |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 228 | public: |
| 229 | /** |
| 230 | * Create a new PrefixEntry. |
| 231 | * @param prefix A shared_ptr for the prefix. |
| 232 | * @param onInterest A function object to call when a matching data packet is received. |
| 233 | */ |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 234 | RegisteredPrefix(const Name& prefix, const OnInterest& onInterest) |
| 235 | : prefix_(new Name(prefix)) |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 236 | , onInterest_(onInterest) |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 237 | { |
| 238 | } |
| 239 | |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 240 | const Name& |
| 241 | getPrefix() const |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 242 | { |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 243 | return *prefix_; |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 244 | } |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 245 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 246 | const OnInterest& |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 247 | getOnInterest() const |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 248 | { |
| 249 | return onInterest_; |
| 250 | } |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 251 | |
| 252 | private: |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 253 | ptr_lib::shared_ptr<Name> prefix_; |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 254 | const OnInterest onInterest_; |
| 255 | }; |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 256 | |
| 257 | // Functor to match pending interests against PendingInterestId |
| 258 | struct MatchRegisteredPrefixId |
| 259 | { |
| 260 | MatchRegisteredPrefixId(const RegisteredPrefixId *registeredPrefixId) |
| 261 | : id_(registeredPrefixId) |
| 262 | { |
| 263 | } |
| 264 | |
| 265 | bool |
| 266 | operator()(const ptr_lib::shared_ptr<RegisteredPrefix> ®isteredPrefix) const |
| 267 | { |
| 268 | return (reinterpret_cast<const RegisteredPrefixId *>(registeredPrefix.get()) == id_); |
| 269 | } |
| 270 | private: |
| 271 | const RegisteredPrefixId *id_; |
| 272 | }; |
| 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 | typedef std::vector<ptr_lib::shared_ptr<PendingInterest> > PendingInterestTable; |
| 276 | typedef std::vector<ptr_lib::shared_ptr<RegisteredPrefix> > RegisteredPrefixTable; |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 277 | |
| 278 | /** |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 279 | * Find the entry from the pit_ where the name conforms to the entry's interest selectors, and |
| 280 | * the entry interest name is the longest that matches name. |
| 281 | * @param name The name to find the interest for (from the incoming data packet). |
| 282 | * @return The index in pit_ of the pit entry, or -1 if not found. |
| 283 | */ |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 284 | PendingInterestTable::iterator |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 285 | getEntryIndexForExpressedInterest(const Name& name); |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 286 | |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 287 | /** |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 288 | * Find the first entry from the registeredPrefixTable_ where the entry prefix is the longest that matches name. |
| 289 | * @param name The name to find the PrefixEntry for (from the incoming interest packet). |
| 290 | * @return A pointer to the entry, or 0 if not found. |
| 291 | */ |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 292 | RegisteredPrefixTable::iterator |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 293 | getEntryForRegisteredPrefix(const Name& name); |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 294 | |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 295 | /** |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 296 | * Do the work of registerPrefix once we know we are connected with an ndndId_. |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 297 | * @param registeredPrefixId The PrefixEntry::getNextRegisteredPrefixId() which registerPrefix got so it could return it to the caller. |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 298 | * @param prefix |
| 299 | * @param onInterest |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 300 | * @param onRegisterFailed |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 301 | * @param flags |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 302 | * @param wireFormat |
| 303 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 304 | void |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 305 | registerPrefixHelper |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 306 | (const ptr_lib::shared_ptr<RegisteredPrefix> &prefixToRegister, |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 307 | const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags); |
| 308 | |
Alexander Afanasyev | 1837187 | 2014-01-05 23:00:26 -0800 | [diff] [blame] | 309 | /** |
| 310 | * @brief Final stage of prefix registration, invoked when registration succeeded |
| 311 | * |
| 312 | * This method actually sets entry in a local interest filter table |
| 313 | */ |
| 314 | void |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 315 | registerPrefixFinal(const ptr_lib::shared_ptr<RegisteredPrefix> &prefixToRegister, |
Alexander Afanasyev | 1837187 | 2014-01-05 23:00:26 -0800 | [diff] [blame] | 316 | const OnRegisterFailed& onRegisterFailed, |
| 317 | const ptr_lib::shared_ptr<const Interest>&, const ptr_lib::shared_ptr<Data>&); |
| 318 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 319 | void |
| 320 | checkPitExpire(); |
| 321 | |
| 322 | private: |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 323 | ptr_lib::shared_ptr<boost::asio::io_service> ioService_; |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 324 | ptr_lib::shared_ptr<boost::asio::io_service::work> ioServiceWork_; // needed if thread needs to be preserved |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 325 | ptr_lib::shared_ptr<boost::asio::deadline_timer> pitTimeoutCheckTimer_; |
Alexander Afanasyev | bf08211 | 2014-01-09 14:27:55 -0800 | [diff] [blame] | 326 | bool pitTimeoutCheckTimerActive_; |
Alexander Afanasyev | e1b7a5d | 2013-12-29 16:23:52 -0800 | [diff] [blame] | 327 | ptr_lib::shared_ptr<boost::asio::deadline_timer> processEventsTimeoutTimer_; |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 328 | |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 329 | ptr_lib::shared_ptr<Transport> transport_; |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 330 | |
| 331 | PendingInterestTable pendingInterestTable_; |
| 332 | RegisteredPrefixTable registeredPrefixTable_; |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 333 | Interest ndndIdFetcherInterest_; |
Alexander Afanasyev | bc343ef | 2014-01-09 22:36:20 -0800 | [diff] [blame] | 334 | |
| 335 | int64_t faceId_; // internal face ID (needed for prefix de-registration) |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 336 | Buffer ndndId_; |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 337 | }; |
| 338 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 339 | } // namespace ndn |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 340 | |
| 341 | #endif |