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" |
| 14 | #include "transport/tcp-transport.hpp" |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 15 | #include "forwarding-flags.hpp" |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 16 | #include "encoding/element-listener.hpp" |
| 17 | |
| 18 | struct ndn_Interest; |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 19 | |
| 20 | namespace ndn { |
| 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 |
Jeff Thompson | b510e3e | 2013-10-07 18:53:20 -0700 | [diff] [blame] | 36 | (const ptr_lib::shared_ptr<const Name>&, const ptr_lib::shared_ptr<const Interest>&, Transport&, uint64_t)> 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 | class KeyChain; |
| 45 | |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 46 | class Node : public ElementListener { |
| 47 | public: |
| 48 | /** |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 49 | * Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo. |
| 50 | * @param transport A shared_ptr to a Transport object used for communication. |
| 51 | * @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] | 52 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 53 | Node(const ptr_lib::shared_ptr<Transport>& transport, const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo); |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 56 | * Send the Interest through the transport, read the entire response and call onData(interest, data). |
| 57 | * @param interest A reference to the Interest. This copies the Interest. |
| 58 | * @param onData A function object to call when a matching data packet is received. This copies the function object, so you may need to |
| 59 | * use func_lib::ref() as appropriate. |
| 60 | * @param onTimeout A function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it. |
| 61 | * 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^] | 62 | * @param wireFormat A WireFormat object used to encode the message. |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 63 | * @return The pending interest ID which can be used with removePendingInterest. |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 64 | */ |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 65 | uint64_t |
Jeff Thompson | 978c152 | 2013-11-12 23:03:10 -0800 | [diff] [blame^] | 66 | expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout, WireFormat& wireFormat); |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 69 | * Remove the pending interest entry with the pendingInterestId from the pending interest table. |
| 70 | * This does not affect another pending interest with a different pendingInterestId, even it if has the same interest name. |
| 71 | * If there is no entry with the pendingInterestId, do nothing. |
| 72 | * @param pendingInterestId The ID returned from expressInterest. |
| 73 | */ |
| 74 | void |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 75 | removePendingInterest(uint64_t pendingInterestId); |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 78 | * Register prefix with the connected NDN hub and call onInterest when a matching interest is received. |
| 79 | * @param prefix A reference to a Name for the prefix to register. This copies the Name. |
| 80 | * @param onInterest A function object to call when a matching interest is received. This copies the function object, so you may need to |
| 81 | * use func_lib::ref() as appropriate. |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 82 | * @param onRegisterFailed A function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. |
| 83 | * This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix. |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 84 | * @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^] | 85 | * @param wireFormat A WireFormat object used to encode the message. |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 86 | * @return The registered prefix ID which can be used with removeRegisteredPrefix. |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 87 | */ |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 88 | uint64_t |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 89 | registerPrefix |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 90 | (const Name& prefix, const OnInterest& onInterest, const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags, |
| 91 | WireFormat& wireFormat); |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 94 | * Remove the registered prefix entry with the registeredPrefixId from the pending interest table. |
| 95 | * This does not affect another registered prefix with a different registeredPrefixId, even it if has the same prefix name. |
| 96 | * If there is no entry with the registeredPrefixId, do nothing. |
| 97 | * @param registeredPrefixId The ID returned from registerPrefix. |
| 98 | */ |
| 99 | void |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 100 | removeRegisteredPrefix(uint64_t registeredPrefixId); |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 103 | * Process any data to receive. For each element received, call onReceivedElement. |
| 104 | * This is non-blocking and will return immediately if there is no data to receive. |
| 105 | * You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn't use 100% of the CPU. |
| 106 | * @throw This may throw an exception for reading data or in the callback for processing the data. If you |
| 107 | * call this from an main event loop, you may want to catch and log/disregard all exceptions. |
| 108 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 109 | void |
| 110 | processEvents(); |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 111 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 112 | const ptr_lib::shared_ptr<Transport>& |
| 113 | getTransport() { return transport_; } |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 114 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 115 | const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& |
| 116 | getConnectionInfo() { return connectionInfo_; } |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 117 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 118 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 119 | onReceivedElement(const uint8_t *element, size_t elementLength); |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 120 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 121 | void |
| 122 | shutdown(); |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 123 | |
| 124 | private: |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 125 | class PendingInterest { |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 126 | public: |
| 127 | /** |
| 128 | * Create a new PitEntry and set the timeoutTime_ based on the current time and the interest lifetime. |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 129 | * @param pendingInterestId A unique ID for this entry, which you should get with getNextPendingInteresId(). |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 130 | * @param interest A shared_ptr for the interest. |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 131 | * @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] | 132 | * @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] | 133 | */ |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 134 | PendingInterest |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 135 | (uint64_t pendingInterestId, const ptr_lib::shared_ptr<const Interest>& interest, const OnData& onData, |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 136 | const OnTimeout& onTimeout); |
| 137 | |
| 138 | /** |
| 139 | * Return the next unique pending interest ID. |
| 140 | */ |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 141 | static uint64_t |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 142 | getNextPendingInterestId() |
| 143 | { |
| 144 | return ++lastPendingInterestId_; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Return the pendingInterestId given to the constructor. |
| 149 | */ |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 150 | uint64_t |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 151 | getPendingInterestId() { return pendingInterestId_; } |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 152 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 153 | const ptr_lib::shared_ptr<const Interest>& |
| 154 | getInterest() { return interest_; } |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 155 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 156 | const OnData& |
| 157 | getOnData() { return onData_; } |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 160 | * Get the struct ndn_Interest for the interest_. |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 161 | * WARNING: Assume that this PitEntry was created with new, so that no copy constructor is invoked between calls. |
| 162 | * This class is private to Node and only used by its methods, so this should be OK. |
| 163 | * TODO: Doesn't this functionality belong in the Interest class? |
| 164 | * @return A reference to the ndn_Interest struct. |
| 165 | * WARNING: The resulting pointers in are invalid uses getInterest() to manipulate the object which could reallocate memory. |
| 166 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 167 | const struct ndn_Interest& |
| 168 | getInterestStruct() |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 169 | { |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 170 | return *interestStruct_; |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
Jeff Thompson | 3b0ed53 | 2013-11-05 13:43:40 -0800 | [diff] [blame] | 174 | * Check if this interest is timed out. |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 175 | * @param nowMilliseconds The current time in milliseconds from ndn_getNowMilliseconds. |
Jeff Thompson | 3b0ed53 | 2013-11-05 13:43:40 -0800 | [diff] [blame] | 176 | * @return true if this interest timed out, otherwise false. |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 177 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 178 | bool |
Jeff Thompson | 3b0ed53 | 2013-11-05 13:43:40 -0800 | [diff] [blame] | 179 | isTimedOut(MillisecondsSince1970 nowMilliseconds) |
| 180 | { |
| 181 | return timeoutTimeMilliseconds_ >= 0.0 && nowMilliseconds >= timeoutTimeMilliseconds_; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Call onTimeout_ (if defined). This ignores exceptions from the onTimeout_. |
| 186 | */ |
| 187 | void |
| 188 | callTimeout(); |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 189 | |
| 190 | private: |
Jeff Thompson | 48917f0 | 2013-08-21 17:12:45 -0700 | [diff] [blame] | 191 | ptr_lib::shared_ptr<const Interest> interest_; |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 192 | std::vector<struct ndn_NameComponent> nameComponents_; |
| 193 | std::vector<struct ndn_ExcludeEntry> excludeEntries_; |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 194 | ptr_lib::shared_ptr<struct ndn_Interest> interestStruct_; |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 195 | |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 196 | static uint64_t lastPendingInterestId_; /**< A class variable used to get the next unique ID. */ |
| 197 | uint64_t pendingInterestId_; /**< A unique identifier for this entry so it can be deleted */ |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 198 | const OnData onData_; |
| 199 | const OnTimeout onTimeout_; |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 200 | 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] | 201 | }; |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 202 | |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 203 | class RegisteredPrefix { |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 204 | public: |
| 205 | /** |
| 206 | * Create a new PrefixEntry. |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 207 | * @param registeredPrefixId A unique ID for this entry, which you should get with getNextRegisteredPrefixId(). |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 208 | * @param prefix A shared_ptr for the prefix. |
| 209 | * @param onInterest A function object to call when a matching data packet is received. |
| 210 | */ |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 211 | RegisteredPrefix(uint64_t registeredPrefixId, const ptr_lib::shared_ptr<const Name>& prefix, const OnInterest& onInterest) |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 212 | : registeredPrefixId_(registeredPrefixId), prefix_(prefix), onInterest_(onInterest) |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 213 | { |
| 214 | } |
| 215 | |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 216 | /** |
| 217 | * Return the next unique entry ID. |
| 218 | */ |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 219 | static uint64_t |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 220 | getNextRegisteredPrefixId() |
| 221 | { |
| 222 | return ++lastRegisteredPrefixId_; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Return the registeredPrefixId given to the constructor. |
| 227 | */ |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 228 | uint64_t |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 229 | getRegisteredPrefixId() { return registeredPrefixId_; } |
| 230 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 231 | const ptr_lib::shared_ptr<const Name>& |
| 232 | getPrefix() { return prefix_; } |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 233 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 234 | const OnInterest& |
| 235 | getOnInterest() { return onInterest_; } |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 236 | |
| 237 | private: |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 238 | static uint64_t lastRegisteredPrefixId_; /**< A class variable used to get the next unique ID. */ |
| 239 | uint64_t registeredPrefixId_; /**< A unique identifier for this entry so it can be deleted */ |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 240 | ptr_lib::shared_ptr<const Name> prefix_; |
| 241 | const OnInterest onInterest_; |
| 242 | }; |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 243 | |
| 244 | /** |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 245 | * An NdndIdFetcher receives the Data packet with the publisher public key digest for the connected NDN hub. |
| 246 | * This class is a function object for the callbacks. It only holds a pointer to an Info object, so it is OK to copy the pointer. |
| 247 | */ |
| 248 | class NdndIdFetcher { |
| 249 | public: |
| 250 | class Info; |
| 251 | NdndIdFetcher(ptr_lib::shared_ptr<NdndIdFetcher::Info> info) |
| 252 | : info_(info) |
| 253 | { |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * We received the ndnd ID. |
| 258 | * @param interest |
| 259 | * @param data |
| 260 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 261 | void |
| 262 | operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData); |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 263 | |
| 264 | /** |
| 265 | * We timed out fetching the ndnd ID. |
| 266 | * @param interest |
| 267 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 268 | void |
| 269 | operator()(const ptr_lib::shared_ptr<const Interest>& timedOutInterest); |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 270 | |
| 271 | class Info { |
| 272 | public: |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 273 | /** |
| 274 | * |
| 275 | * @param node |
| 276 | * @param registeredPrefixId The PrefixEntry::getNextRegisteredPrefixId() which registerPrefix got so it could return it to the caller. |
| 277 | * @param prefix |
| 278 | * @param onInterest |
| 279 | * @param onRegisterFailed |
| 280 | * @param flags |
| 281 | * @param wireFormat |
| 282 | */ |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 283 | Info(Node *node, uint64_t registeredPrefixId, const Name& prefix, const OnInterest& onInterest, |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 284 | const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags, WireFormat& wireFormat) |
| 285 | : node_(*node), registeredPrefixId_(registeredPrefixId), prefix_(new Name(prefix)), onInterest_(onInterest), onRegisterFailed_(onRegisterFailed), |
Jeff Thompson | 6d7369b | 2013-09-19 14:40:21 -0700 | [diff] [blame] | 286 | flags_(flags), wireFormat_(wireFormat) |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 287 | { |
| 288 | } |
| 289 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 290 | Node& node_; |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 291 | uint64_t registeredPrefixId_; |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 292 | ptr_lib::shared_ptr<const Name> prefix_; |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 293 | const OnInterest onInterest_; |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 294 | const OnRegisterFailed onRegisterFailed_; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 295 | ForwardingFlags flags_; |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 296 | WireFormat& wireFormat_; |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | private: |
| 300 | ptr_lib::shared_ptr<Info> info_; |
| 301 | }; |
| 302 | |
| 303 | /** |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 304 | * Find the entry from the pit_ where the name conforms to the entry's interest selectors, and |
| 305 | * the entry interest name is the longest that matches name. |
| 306 | * @param name The name to find the interest for (from the incoming data packet). |
| 307 | * @return The index in pit_ of the pit entry, or -1 if not found. |
| 308 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 309 | int |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 310 | getEntryIndexForExpressedInterest(const Name& name); |
Jeff Thompson | 557b81e | 2013-08-21 15:13:51 -0700 | [diff] [blame] | 311 | |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 312 | /** |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 313 | * Find the first entry from the registeredPrefixTable_ where the entry prefix is the longest that matches name. |
| 314 | * @param name The name to find the PrefixEntry for (from the incoming interest packet). |
| 315 | * @return A pointer to the entry, or 0 if not found. |
| 316 | */ |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 317 | RegisteredPrefix* |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 318 | getEntryForRegisteredPrefix(const Name& name); |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 319 | |
Jeff Thompson | 9cc4be4 | 2013-08-27 18:12:41 -0700 | [diff] [blame] | 320 | /** |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 321 | * 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] | 322 | * @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] | 323 | * @param prefix |
| 324 | * @param onInterest |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 325 | * @param onRegisterFailed |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 326 | * @param flags |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 327 | * @param wireFormat |
| 328 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 329 | void |
Jeff Thompson | 590ec23 | 2013-09-18 15:55:56 -0700 | [diff] [blame] | 330 | registerPrefixHelper |
Jeff Thompson | 62992e4 | 2013-10-07 18:50:51 -0700 | [diff] [blame] | 331 | (uint64_t registeredPrefixId, const ptr_lib::shared_ptr<const Name>& prefix, const OnInterest& onInterest, |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 332 | const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags, WireFormat& wireFormat); |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 333 | |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 334 | ptr_lib::shared_ptr<Transport> transport_; |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 335 | ptr_lib::shared_ptr<const Transport::ConnectionInfo> connectionInfo_; |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 336 | std::vector<ptr_lib::shared_ptr<PendingInterest> > pendingInterestTable_; |
| 337 | std::vector<ptr_lib::shared_ptr<RegisteredPrefix> > registeredPrefixTable_; |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 338 | Interest ndndIdFetcherInterest_; |
Jeff Thompson | 03616c9 | 2013-09-12 14:30:01 -0700 | [diff] [blame] | 339 | Blob ndndId_; |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
| 342 | } |
| 343 | |
| 344 | #endif |