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 | aa4e6db | 2013-07-15 17:25:23 -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. |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 7 | #ifndef NDN_FACE_HPP |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 8 | #define NDN_FACE_HPP |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 9 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 10 | #include "common.hpp" |
| 11 | #include "interest.hpp" |
| 12 | #include "data.hpp" |
| 13 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 14 | #include "transport/transport.hpp" |
| 15 | #include "transport/unix-transport.hpp" |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 16 | #include "transport/tcp-transport.hpp" |
Jeff Thompson | beb8b7d | 2013-07-16 15:49:21 -0700 | [diff] [blame] | 17 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 18 | #include "management/controller.hpp" |
| 19 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 20 | #include "util/scheduler.hpp" |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 21 | #include "detail/registered-prefix.hpp" |
| 22 | #include "detail/pending-interest.hpp" |
| 23 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 24 | namespace ndn { |
| 25 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 26 | struct PendingInterestId; |
| 27 | struct RegisteredPrefixId; |
| 28 | |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 29 | /** |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 30 | * An OnData function object is used to pass a callback to expressInterest. |
| 31 | */ |
| 32 | typedef function<void(const Interest&, Data&)> OnData; |
| 33 | |
| 34 | /** |
| 35 | * An OnTimeout function object is used to pass a callback to expressInterest. |
| 36 | */ |
| 37 | typedef function<void(const Interest&)> OnTimeout; |
| 38 | |
| 39 | /** |
| 40 | * An OnInterest function object is used to pass a callback to registerPrefix. |
| 41 | */ |
| 42 | typedef function<void (const Name&, const Interest&)> OnInterest; |
| 43 | |
| 44 | /** |
| 45 | * An OnRegisterFailed function object is used to report when registerPrefix fails. |
| 46 | */ |
| 47 | typedef function<void(const Name&, const std::string&)> OnSetInterestFilterFailed; |
| 48 | |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * @brief Abstraction to communicate with local or remote NDN forwarder |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 53 | */ |
Alexander Afanasyev | 8460afb | 2014-02-15 20:31:42 -0800 | [diff] [blame] | 54 | class Face : noncopyable |
| 55 | { |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 56 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 57 | class Error : public std::runtime_error |
| 58 | { |
| 59 | public: |
| 60 | explicit |
| 61 | Error(const std::string& what) |
| 62 | : std::runtime_error(what) |
| 63 | { |
| 64 | } |
| 65 | }; |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 66 | |
| 67 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 68 | * @brief Create a new Face using the default transport (UnixTransport) |
| 69 | * |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 70 | * @throws ConfigFile::Error on configuration file parse failure |
| 71 | * @throws Face::Error on unsupported protocol |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 72 | */ |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 73 | Face(); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 76 | * @brief Create a new Face using the default transport (UnixTransport) |
| 77 | * |
| 78 | * @deprecated This constructor is deprecated. Use `Face(boost::asio::io_service&)` |
| 79 | * instead. |
| 80 | * |
| 81 | * @param ioService A shared pointer to boost::io_service object that should control all |
| 82 | * IO operations |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 83 | * @throws ConfigFile::Error on configuration file parse failure |
| 84 | * @throws Face::Error on unsupported protocol |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 85 | */ |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 86 | explicit |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 87 | Face(const shared_ptr<boost::asio::io_service>& ioService); |
| 88 | |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 89 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 90 | * @brief Create a new Face using the default transport (UnixTransport) |
| 91 | * |
| 92 | * @par Usage examples: |
| 93 | * |
| 94 | * Face face1; |
| 95 | * Face face2(face1.getIoService()); |
| 96 | * |
| 97 | * // Now the following ensures that events on both faces are processed |
| 98 | * face1.processEvents(); |
| 99 | * // or face1.getIoService().run(); |
| 100 | * |
| 101 | * @par or |
| 102 | * |
| 103 | * boost::asio::io_service ioService; |
| 104 | * Face face1(ioService); |
| 105 | * Face face2(ioService); |
| 106 | * ... |
| 107 | * |
| 108 | * ioService.run(); |
| 109 | * |
| 110 | * @param ioService A reference to boost::io_service object that should control all |
| 111 | * IO operations. |
| 112 | * @throws ConfigFile::Error on configuration file parse failure |
| 113 | * @throws Face::Error on unsupported protocol |
| 114 | */ |
| 115 | explicit |
| 116 | Face(boost::asio::io_service& ioService); |
| 117 | |
| 118 | /** |
| 119 | * @brief Create a new Face using TcpTransport |
| 120 | * |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 121 | * @param host The host of the NDN hub. |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 122 | * @param port The port or service name of the NDN hub. If omitted. use 6363. |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 123 | * @throws Face::Error on unsupported protocol |
Jeff Thompson | fe08e5a | 2013-08-13 11:15:59 -0700 | [diff] [blame] | 124 | */ |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 125 | Face(const std::string& host, const std::string& port = "6363"); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 126 | |
| 127 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 128 | * @brief Create a new Face using the given Transport |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 129 | * @param transport A shared_ptr to a Transport object used for communication. |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 130 | * @throws Face::Error on unsupported protocol |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 131 | */ |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 132 | explicit |
| 133 | Face(const shared_ptr<Transport>& transport); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 134 | |
| 135 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 136 | * @brief Create a new Face using the given Transport and IO service object |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 137 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 138 | * @sa Face(boost::asio::io_service&) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 139 | * |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 140 | * @throws Face::Error on unsupported protocol |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 141 | */ |
| 142 | Face(const shared_ptr<Transport>& transport, |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 143 | boost::asio::io_service& ioService); |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 144 | |
| 145 | /** |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 146 | * @brief Set controller used for prefix registration |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 147 | */ |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 148 | void |
| 149 | setController(const shared_ptr<Controller>& controller); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 150 | |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 151 | /** |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 152 | * @brief Express Interest |
| 153 | * |
| 154 | * @param interest A reference to the Interest. This copies the Interest. |
| 155 | * @param onData A function object to call when a matching data packet is received. |
| 156 | * @param onTimeout A function object to call if the interest times out. |
| 157 | * If onTimeout is an empty OnTimeout(), this does not use it. |
| 158 | * |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 159 | * @return The pending interest ID which can be used with removePendingInterest. |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 160 | */ |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 161 | const PendingInterestId* |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 162 | expressInterest(const Interest& interest, |
| 163 | const OnData& onData, const OnTimeout& onTimeout = OnTimeout()); |
Jeff Thompson | 4fe4551 | 2013-08-23 14:06:38 -0700 | [diff] [blame] | 164 | |
| 165 | /** |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 166 | * @brief Express Interest using name and Interest template |
| 167 | * |
| 168 | * @param name Name of the Interest |
| 169 | * @param tmpl Interest template to fill parameters |
| 170 | * @param onData A callback to call when a matching data packet is received. |
| 171 | * @param onTimeout A callback to call if the interest times out. |
| 172 | * If onTimeout is an empty OnTimeout(), this does not use it. |
| 173 | * |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 174 | * @return The pending interest ID which can be used with removePendingInterest. |
Jeff Thompson | 7aec025 | 2013-08-22 17:29:57 -0700 | [diff] [blame] | 175 | */ |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 176 | const PendingInterestId* |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 177 | expressInterest(const Name& name, |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 178 | const Interest& tmpl, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 179 | const OnData& onData, const OnTimeout& onTimeout = OnTimeout()); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 180 | |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 181 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 182 | * @brief Remove the pending interest entry with the pendingInterestId from the pending |
| 183 | * interest table. |
| 184 | * |
| 185 | * This does not affect another pending interest with a different pendingInterestId, |
| 186 | * even it if has the same interest name. If there is no entry with the |
| 187 | * pendingInterestId, do nothing. |
| 188 | * |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 189 | * @param pendingInterestId The ID returned from expressInterest. |
| 190 | */ |
| 191 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 192 | removePendingInterest(const PendingInterestId* pendingInterestId); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 193 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 194 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 195 | * @brief Register prefix with the connected NDN hub and call onInterest when a matching |
| 196 | * interest is received. |
| 197 | * |
| 198 | * @param prefix A reference to a Name for the prefix to register |
| 199 | * @param onInterest A function object to call when a matching interest is received |
| 200 | * |
| 201 | * @param onRegisterFailed A function object to call if failed to retrieve the connected |
| 202 | * hub’s ID or failed to register the prefix. This calls |
| 203 | * onRegisterFailed(prefix) where prefix is the prefix given to |
| 204 | * registerPrefix. |
| 205 | * |
| 206 | * @param flags The flags for finer control of which interests are forward to the |
| 207 | * application. |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 208 | * @return The registered prefix ID which can be used with removeRegisteredPrefix. |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 209 | */ |
Alexander Afanasyev | b790d95 | 2014-01-24 12:07:53 -0800 | [diff] [blame] | 210 | const RegisteredPrefixId* |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 211 | setInterestFilter(const Name& prefix, |
| 212 | const OnInterest& onInterest, |
| 213 | const OnSetInterestFilterFailed& onSetInterestFilterFailed); |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 214 | |
| 215 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 216 | * @brief Remove the registered prefix entry with the registeredPrefixId from the |
| 217 | * pending interest table. |
| 218 | * |
| 219 | * This does not affect another registered prefix with a different registeredPrefixId, |
| 220 | * even it if has the same prefix name. If there is no entry with the |
| 221 | * registeredPrefixId, do nothing. |
| 222 | * |
Jeff Thompson | 1109514 | 2013-10-01 16:20:28 -0700 | [diff] [blame] | 223 | * @param registeredPrefixId The ID returned from registerPrefix. |
| 224 | */ |
| 225 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 226 | unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId); |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 227 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 228 | /** |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 229 | * @brief Publish data packet |
| 230 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 231 | * This method can be called to satisfy the incoming Interest or to put Data packet into |
| 232 | * the cache of the local NDN forwarder |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 233 | */ |
| 234 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 235 | put(const Data& data); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 236 | |
Jeff Thompson | 86507bc | 2013-08-23 20:51:38 -0700 | [diff] [blame] | 237 | /** |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 238 | * @brief Process any data to receive or call timeout callbacks. |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 239 | * |
| 240 | * This call will block forever (default timeout == 0) to process IO on the face. |
| 241 | * To exit, one expected to call face.shutdown() from one of the callback methods. |
| 242 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 243 | * If positive timeout is specified, then processEvents will exit after this timeout, if |
| 244 | * not stopped earlier with face.shutdown() or when all active events finish. The call |
| 245 | * can be called repeatedly, if desired. |
Alexander Afanasyev | a557d5a | 2013-12-28 21:59:03 -0800 | [diff] [blame] | 246 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 247 | * If negative timeout is specified, then processEvents will not block and process only |
| 248 | * pending events. |
Alexander Afanasyev | f75a0aa | 2014-01-09 14:29:22 -0800 | [diff] [blame] | 249 | * |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 250 | * @param timeout maximum time to block the thread. |
| 251 | * @param keepThread Keep thread in a blocked state (in event processing), even when |
| 252 | * there are no outstanding events (e.g., no Interest/Data is expected) |
| 253 | * |
| 254 | * @throw This may throw an exception for reading data or in the callback for processing |
| 255 | * the data. If you call this from an main event loop, you may want to catch and |
| 256 | * log/disregard all exceptions. |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 257 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 258 | void |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 259 | processEvents(const time::milliseconds& timeout = time::milliseconds::zero(), |
| 260 | bool keepThread = false); |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 261 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 262 | /** |
| 263 | * @brief Shutdown face operations |
| 264 | * |
| 265 | * This method cancels all pending operations and closes connection to NDN Forwarder. |
| 266 | * |
| 267 | * Note that this method does not stop IO service and if the same IO service is shared |
| 268 | * between multiple Faces or with other IO objects (e.g., Scheduler). |
| 269 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 270 | void |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 271 | shutdown(); |
Yingdi Yu | 0d92081 | 2014-01-30 14:50:57 -0800 | [diff] [blame] | 272 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 273 | /** |
| 274 | * @brief Get shared_ptr of the IO service object |
| 275 | * |
| 276 | * @deprecated Use getIoService instead |
| 277 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 278 | shared_ptr<boost::asio::io_service> |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 279 | ioService() |
| 280 | { |
| 281 | return m_ioService; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * @brief Get reference to IO service object |
| 286 | */ |
| 287 | boost::asio::io_service& |
| 288 | getIoService() |
| 289 | { |
| 290 | return *m_ioService; |
| 291 | } |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 292 | |
| 293 | private: |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * @throws Face::Error on unsupported protocol |
| 297 | */ |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 298 | void |
Alexander Afanasyev | 7682ccb | 2014-02-20 10:29:35 -0800 | [diff] [blame] | 299 | construct(const shared_ptr<Transport>& transport, |
Alexander Afanasyev | 505646e | 2014-02-24 20:13:37 -0800 | [diff] [blame] | 300 | const shared_ptr<boost::asio::io_service>& ioService); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 301 | |
| 302 | bool |
| 303 | isSupportedNfdProtocol(const std::string& protocol); |
| 304 | |
| 305 | bool |
| 306 | isSupportedNrdProtocol(const std::string& protocol); |
| 307 | |
| 308 | bool |
| 309 | isSupportedNdndProtocol(const std::string& protocol); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 310 | |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 311 | class ProcessEventsTimeout |
| 312 | { |
| 313 | }; |
| 314 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 315 | typedef std::list<shared_ptr<PendingInterest> > PendingInterestTable; |
| 316 | typedef std::list<shared_ptr<RegisteredPrefix> > RegisteredPrefixTable; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 317 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 318 | void |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 319 | asyncExpressInterest(const shared_ptr<const Interest>& interest, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 320 | const OnData& onData, const OnTimeout& onTimeout); |
| 321 | |
| 322 | void |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 323 | asyncRemovePendingInterest(const PendingInterestId* pendingInterestId); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 324 | |
| 325 | void |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 326 | asyncUnsetInterestFilter(const RegisteredPrefixId* registeredPrefixId); |
Alexander Afanasyev | 12dfbad | 2014-02-11 14:42:46 -0800 | [diff] [blame] | 327 | |
| 328 | void |
Alexander Afanasyev | 52afb3f | 2014-03-07 09:05:35 +0000 | [diff] [blame] | 329 | finalizeUnsetInterestFilter(RegisteredPrefixTable::iterator item); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 330 | |
| 331 | void |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 332 | onReceiveElement(const Block& wire); |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 333 | |
Alexander Afanasyev | 7dced46 | 2014-03-19 15:12:32 -0700 | [diff] [blame] | 334 | void |
| 335 | asyncShutdown(); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 336 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 337 | static void |
| 338 | fireProcessEventsTimeout(const boost::system::error_code& error); |
| 339 | |
Alexander Afanasyev | 42c8185 | 2014-02-25 21:37:26 -0800 | [diff] [blame] | 340 | void |
| 341 | satisfyPendingInterests(Data& data); |
| 342 | |
| 343 | void |
| 344 | processInterestFilters(Interest& interest); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 345 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 346 | void |
| 347 | checkPitExpire(); |
Yingdi Yu | f9fa52f | 2014-02-06 12:27:32 -0800 | [diff] [blame] | 348 | |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 349 | private: |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 350 | shared_ptr<boost::asio::io_service> m_ioService; |
Alexander Afanasyev | 691c3ce | 2014-04-23 14:28:04 -0700 | [diff] [blame^] | 351 | shared_ptr<boost::asio::io_service::work> m_ioServiceWork; // if thread needs to be preserved |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 352 | shared_ptr<monotonic_deadline_timer> m_pitTimeoutCheckTimer; |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 353 | bool m_pitTimeoutCheckTimerActive; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 354 | shared_ptr<monotonic_deadline_timer> m_processEventsTimeoutTimer; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 355 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 356 | shared_ptr<Transport> m_transport; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 357 | |
Alexander Afanasyev | f39c537 | 2014-02-17 19:42:56 -0800 | [diff] [blame] | 358 | PendingInterestTable m_pendingInterestTable; |
| 359 | RegisteredPrefixTable m_registeredPrefixTable; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 360 | |
| 361 | shared_ptr<Controller> m_fwController; |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 362 | |
| 363 | ConfigFile m_config; |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 364 | }; |
| 365 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 366 | inline bool |
| 367 | Face::isSupportedNfdProtocol(const std::string& protocol) |
| 368 | { |
| 369 | return protocol == "nfd-0.1"; |
| 370 | } |
| 371 | |
| 372 | inline bool |
| 373 | Face::isSupportedNrdProtocol(const std::string& protocol) |
| 374 | { |
| 375 | return protocol == "nrd-0.1"; |
| 376 | } |
| 377 | |
| 378 | inline bool |
| 379 | Face::isSupportedNdndProtocol(const std::string& protocol) |
| 380 | { |
| 381 | return protocol == "ndnd-tlv-0.7"; |
| 382 | } |
| 383 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 384 | } // namespace ndn |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 385 | |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 386 | #endif // NDN_FACE_HPP |