Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face-manager.hpp" |
| 27 | |
| 28 | #include "core/network-interface.hpp" |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame] | 29 | #include "face/generic-link-service.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 30 | #include "face/tcp-factory.hpp" |
| 31 | #include "face/udp-factory.hpp" |
Yukai Tu | 0a49d34 | 2015-09-13 12:54:22 +0800 | [diff] [blame] | 32 | #include "fw/face-table.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 33 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/management/nfd-channel-status.hpp> |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 35 | #include <ndn-cxx/management/nfd-face-status.hpp> |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 36 | #include <ndn-cxx/management/nfd-face-event-notification.hpp> |
| 37 | |
| 38 | #ifdef HAVE_UNIX_SOCKETS |
| 39 | #include "face/unix-stream-factory.hpp" |
| 40 | #endif // HAVE_UNIX_SOCKETS |
| 41 | |
| 42 | #ifdef HAVE_LIBPCAP |
| 43 | #include "face/ethernet-factory.hpp" |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 44 | #include "face/ethernet-transport.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 45 | #endif // HAVE_LIBPCAP |
| 46 | |
| 47 | #ifdef HAVE_WEBSOCKET |
| 48 | #include "face/websocket-factory.hpp" |
| 49 | #endif // HAVE_WEBSOCKET |
| 50 | |
| 51 | namespace nfd { |
| 52 | |
| 53 | NFD_LOG_INIT("FaceManager"); |
| 54 | |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 55 | FaceManager::FaceManager(FaceTable& faceTable, Dispatcher& dispatcher, CommandAuthenticator& authenticator) |
| 56 | : NfdManagerBase(dispatcher, authenticator, "faces") |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 57 | , m_faceTable(faceTable) |
| 58 | { |
| 59 | registerCommandHandler<ndn::nfd::FaceCreateCommand>("create", |
| 60 | bind(&FaceManager::createFace, this, _2, _3, _4, _5)); |
| 61 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame^] | 62 | registerCommandHandler<ndn::nfd::FaceUpdateCommand>("update", |
| 63 | bind(&FaceManager::updateFace, this, _2, _3, _4, _5)); |
| 64 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 65 | registerCommandHandler<ndn::nfd::FaceDestroyCommand>("destroy", |
| 66 | bind(&FaceManager::destroyFace, this, _2, _3, _4, _5)); |
| 67 | |
| 68 | registerCommandHandler<ndn::nfd::FaceEnableLocalControlCommand>("enable-local-control", |
| 69 | bind(&FaceManager::enableLocalControl, this, _2, _3, _4, _5)); |
| 70 | |
| 71 | registerCommandHandler<ndn::nfd::FaceDisableLocalControlCommand>("disable-local-control", |
| 72 | bind(&FaceManager::disableLocalControl, this, _2, _3, _4, _5)); |
| 73 | |
| 74 | registerStatusDatasetHandler("list", bind(&FaceManager::listFaces, this, _1, _2, _3)); |
| 75 | registerStatusDatasetHandler("channels", bind(&FaceManager::listChannels, this, _1, _2, _3)); |
| 76 | registerStatusDatasetHandler("query", bind(&FaceManager::queryFaces, this, _1, _2, _3)); |
| 77 | |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 78 | m_postNotification = registerNotificationStream("events"); |
| 79 | m_faceAddConn = m_faceTable.afterAdd.connect(bind(&FaceManager::notifyAddFace, this, _1)); |
| 80 | m_faceRemoveConn = m_faceTable.beforeRemove.connect(bind(&FaceManager::notifyRemoveFace, this, _1)); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void |
| 84 | FaceManager::setConfigFile(ConfigFile& configFile) |
| 85 | { |
| 86 | configFile.addSectionHandler("face_system", bind(&FaceManager::processConfig, this, _1, _2, _3)); |
| 87 | } |
| 88 | |
| 89 | void |
| 90 | FaceManager::createFace(const Name& topPrefix, const Interest& interest, |
| 91 | const ControlParameters& parameters, |
| 92 | const ndn::mgmt::CommandContinuation& done) |
| 93 | { |
| 94 | FaceUri uri; |
| 95 | if (!uri.parse(parameters.getUri())) { |
| 96 | NFD_LOG_TRACE("failed to parse URI"); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 97 | done(ControlResponse(400, "Malformed command")); |
| 98 | return; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | if (!uri.isCanonical()) { |
| 102 | NFD_LOG_TRACE("received non-canonical URI"); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 103 | done(ControlResponse(400, "Non-canonical URI")); |
| 104 | return; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 107 | auto factory = m_factories.find(uri.getScheme()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 108 | if (factory == m_factories.end()) { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 109 | NFD_LOG_TRACE("received create request for unsupported protocol"); |
| 110 | done(ControlResponse(406, "Unsupported protocol")); |
| 111 | return; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | try { |
| 115 | factory->second->createFace(uri, |
| 116 | parameters.getFacePersistency(), |
| 117 | bind(&FaceManager::afterCreateFaceSuccess, |
| 118 | this, parameters, _1, done), |
| 119 | bind(&FaceManager::afterCreateFaceFailure, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 120 | this, _1, _2, done)); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 121 | } |
| 122 | catch (const std::runtime_error& error) { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 123 | NFD_LOG_ERROR("Face creation failed: " << error.what()); |
| 124 | done(ControlResponse(500, "Face creation failed due to internal error")); |
| 125 | return; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 126 | } |
| 127 | catch (const std::logic_error& error) { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 128 | NFD_LOG_ERROR("Face creation failed: " << error.what()); |
| 129 | done(ControlResponse(500, "Face creation failed due to internal error")); |
| 130 | return; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 134 | /** |
| 135 | * \todo #3232 |
| 136 | * If the creation of this face would conflict with an existing face (e.g. same underlying |
| 137 | * protocol and remote address, or a NIC-associated permanent face), the command will fail |
| 138 | * with StatusCode 409. |
| 139 | */ |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 140 | void |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 141 | FaceManager::afterCreateFaceSuccess(const ControlParameters& parameters, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 142 | const shared_ptr<Face>& newFace, |
| 143 | const ndn::mgmt::CommandContinuation& done) |
| 144 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 145 | ControlParameters response; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 146 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 147 | m_faceTable.add(newFace); |
| 148 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame^] | 149 | // TODO: #3731: Verify and add Flags |
| 150 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 151 | // Set ControlResponse parameters |
| 152 | response.setFaceId(newFace->getId()); |
| 153 | response.setFacePersistency(newFace->getPersistency()); |
| 154 | |
| 155 | done(ControlResponse(200, "OK").setBody(response.wireEncode())); |
| 156 | } |
| 157 | |
| 158 | void |
| 159 | FaceManager::afterCreateFaceFailure(uint32_t status, |
| 160 | const std::string& reason, |
| 161 | const ndn::mgmt::CommandContinuation& done) |
| 162 | { |
| 163 | NFD_LOG_DEBUG("Face creation failed: " << reason); |
| 164 | |
| 165 | done(ControlResponse(status, reason)); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame^] | 169 | FaceManager::updateFace(const Name& topPrefix, const Interest& interest, |
| 170 | const ControlParameters& parameters, |
| 171 | const ndn::mgmt::CommandContinuation& done) |
| 172 | { |
| 173 | FaceId faceId = parameters.getFaceId(); |
| 174 | if (faceId == 0) { |
| 175 | // Self-updating |
| 176 | shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = interest.getTag<lp::IncomingFaceIdTag>(); |
| 177 | if (incomingFaceIdTag == nullptr) { |
| 178 | NFD_LOG_TRACE("unable to determine face for self-update"); |
| 179 | done(ControlResponse(404, "No FaceId specified and IncomingFaceId not available")); |
| 180 | return; |
| 181 | } |
| 182 | faceId = *incomingFaceIdTag; |
| 183 | } |
| 184 | |
| 185 | Face* face = m_faceTable.get(faceId); |
| 186 | |
| 187 | if (face == nullptr) { |
| 188 | NFD_LOG_TRACE("invalid face specified"); |
| 189 | done(ControlResponse(404, "Specified face does not exist")); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | // Verify validity of requested changes |
| 194 | ControlParameters response; |
| 195 | bool areParamsValid = true; |
| 196 | |
| 197 | if (parameters.hasFacePersistency()) { |
| 198 | // TODO #3232: Add FacePersistency updating |
| 199 | NFD_LOG_TRACE("received unsupported face persistency change"); |
| 200 | areParamsValid = false; |
| 201 | response.setFacePersistency(parameters.getFacePersistency()); |
| 202 | } |
| 203 | |
| 204 | if (parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) && |
| 205 | parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) && |
| 206 | face->getScope() != ndn::nfd::FACE_SCOPE_LOCAL) { |
| 207 | NFD_LOG_TRACE("received request to enable local fields on non-local face"); |
| 208 | areParamsValid = false; |
| 209 | response.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, |
| 210 | parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 211 | } |
| 212 | |
| 213 | if (!areParamsValid) { |
| 214 | done(ControlResponse(409, "Invalid properties specified").setBody(response.wireEncode())); |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | // All specified properties are valid, so make changes |
| 219 | |
| 220 | // TODO #3232: Add FacePersistency updating |
| 221 | |
| 222 | setLinkServiceOptions(*face, parameters, response); |
| 223 | |
| 224 | // Set remaining ControlResponse fields |
| 225 | response.setFaceId(faceId); |
| 226 | response.setFacePersistency(face->getPersistency()); |
| 227 | |
| 228 | done(ControlResponse(200, "OK").setBody(response.wireEncode())); |
| 229 | } |
| 230 | |
| 231 | void |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame] | 232 | FaceManager::destroyFace(const Name& topPrefix, const Interest& interest, |
| 233 | const ControlParameters& parameters, |
| 234 | const ndn::mgmt::CommandContinuation& done) |
| 235 | { |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame] | 236 | Face* face = m_faceTable.get(parameters.getFaceId()); |
| 237 | if (face != nullptr) { |
| 238 | face->close(); |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | done(ControlResponse(200, "OK").setBody(parameters.wireEncode())); |
| 242 | } |
| 243 | |
| 244 | void |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame] | 245 | FaceManager::enableLocalControl(const Name& topPrefix, const Interest& interest, |
| 246 | const ControlParameters& parameters, |
| 247 | const ndn::mgmt::CommandContinuation& done) |
| 248 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 249 | Face* face = findFaceForLocalControl(interest, parameters, done); |
| 250 | if (!face) { |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame] | 251 | return; |
| 252 | } |
| 253 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame^] | 254 | // enable-local-control will enable all local fields in GenericLinkService |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 255 | auto service = dynamic_cast<face::GenericLinkService*>(face->getLinkService()); |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame] | 256 | if (service == nullptr) { |
| 257 | return done(ControlResponse(503, "LinkService type not supported")); |
| 258 | } |
| 259 | |
| 260 | face::GenericLinkService::Options options = service->getOptions(); |
| 261 | options.allowLocalFields = true; |
| 262 | service->setOptions(options); |
| 263 | |
| 264 | return done(ControlResponse(200, "OK: enable all local fields on GenericLinkService") |
| 265 | .setBody(parameters.wireEncode())); |
| 266 | } |
| 267 | |
| 268 | void |
| 269 | FaceManager::disableLocalControl(const Name& topPrefix, const Interest& interest, |
| 270 | const ControlParameters& parameters, |
| 271 | const ndn::mgmt::CommandContinuation& done) |
| 272 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 273 | Face* face = findFaceForLocalControl(interest, parameters, done); |
| 274 | if (!face) { |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame] | 275 | return; |
| 276 | } |
| 277 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame^] | 278 | // disable-local-control will disable all local fields in GenericLinkService |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 279 | auto service = dynamic_cast<face::GenericLinkService*>(face->getLinkService()); |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame] | 280 | if (service == nullptr) { |
| 281 | return done(ControlResponse(503, "LinkService type not supported")); |
| 282 | } |
| 283 | |
| 284 | face::GenericLinkService::Options options = service->getOptions(); |
| 285 | options.allowLocalFields = false; |
| 286 | service->setOptions(options); |
| 287 | |
| 288 | return done(ControlResponse(200, "OK: disable all local fields on GenericLinkService") |
| 289 | .setBody(parameters.wireEncode())); |
| 290 | } |
| 291 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 292 | Face* |
| 293 | FaceManager::findFaceForLocalControl(const Interest& request, |
| 294 | const ControlParameters& parameters, |
| 295 | const ndn::mgmt::CommandContinuation& done) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 296 | { |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 297 | shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>(); |
| 298 | // NDNLPv2 says "application MUST be prepared to receive a packet without IncomingFaceId field", |
| 299 | // but it's fine to assert IncomingFaceId is available, because InternalFace lives inside NFD |
| 300 | // and is initialized synchronously with IncomingFaceId field enabled. |
| 301 | BOOST_ASSERT(incomingFaceIdTag != nullptr); |
| 302 | |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame] | 303 | Face* face = m_faceTable.get(*incomingFaceIdTag); |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 304 | if (face == nullptr) { |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 305 | NFD_LOG_DEBUG("FaceId " << *incomingFaceIdTag << " not found"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 306 | done(ControlResponse(410, "Face not found")); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 307 | return nullptr; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 310 | if (face->getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 311 | NFD_LOG_DEBUG("Cannot enable local control on non-local FaceId " << face->getId()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 312 | done(ControlResponse(412, "Face is non-local")); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 313 | return nullptr; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Junxiao Shi | 5b43f9a | 2016-07-19 13:15:56 +0000 | [diff] [blame] | 316 | return face; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame^] | 320 | FaceManager::setLinkServiceOptions(Face& face, |
| 321 | const ControlParameters& parameters, |
| 322 | ControlParameters& response) |
| 323 | { |
| 324 | auto linkService = dynamic_cast<face::GenericLinkService*>(face.getLinkService()); |
| 325 | BOOST_ASSERT(linkService != nullptr); |
| 326 | |
| 327 | auto options = linkService->getOptions(); |
| 328 | if (parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) && |
| 329 | face.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) { |
| 330 | options.allowLocalFields = parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED); |
| 331 | } |
| 332 | linkService->setOptions(options); |
| 333 | |
| 334 | // Set Flags for ControlResponse |
| 335 | response.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, options.allowLocalFields, false); |
| 336 | } |
| 337 | |
| 338 | void |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 339 | FaceManager::listFaces(const Name& topPrefix, const Interest& interest, |
| 340 | ndn::mgmt::StatusDatasetContext& context) |
| 341 | { |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 342 | auto now = time::steady_clock::now(); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 343 | for (const Face& face : m_faceTable) { |
| 344 | ndn::nfd::FaceStatus status = collectFaceStatus(face, now); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 345 | context.append(status.wireEncode()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 346 | } |
| 347 | context.end(); |
| 348 | } |
| 349 | |
| 350 | void |
| 351 | FaceManager::listChannels(const Name& topPrefix, const Interest& interest, |
| 352 | ndn::mgmt::StatusDatasetContext& context) |
| 353 | { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 354 | std::set<const ProtocolFactory*> seenFactories; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 355 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 356 | for (const auto& kv : m_factories) { |
| 357 | const ProtocolFactory* factory = kv.second.get(); |
| 358 | bool inserted; |
| 359 | std::tie(std::ignore, inserted) = seenFactories.insert(factory); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 360 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 361 | if (inserted) { |
| 362 | for (const auto& channel : factory->getChannels()) { |
| 363 | ndn::nfd::ChannelStatus entry; |
| 364 | entry.setLocalUri(channel->getUri().toString()); |
| 365 | context.append(entry.wireEncode()); |
| 366 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
| 370 | context.end(); |
| 371 | } |
| 372 | |
| 373 | void |
| 374 | FaceManager::queryFaces(const Name& topPrefix, const Interest& interest, |
| 375 | ndn::mgmt::StatusDatasetContext& context) |
| 376 | { |
| 377 | ndn::nfd::FaceQueryFilter faceFilter; |
| 378 | const Name& query = interest.getName(); |
| 379 | try { |
| 380 | faceFilter.wireDecode(query[-1].blockFromValue()); |
| 381 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 382 | catch (const tlv::Error& e) { |
| 383 | NFD_LOG_DEBUG("Malformed query filter: " << e.what()); |
| 384 | return context.reject(ControlResponse(400, "Malformed filter")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 387 | auto now = time::steady_clock::now(); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 388 | for (const Face& face : m_faceTable) { |
| 389 | if (!matchFilter(faceFilter, face)) { |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 390 | continue; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 391 | } |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 392 | ndn::nfd::FaceStatus status = collectFaceStatus(face, now); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 393 | context.append(status.wireEncode()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 394 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 395 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 396 | context.end(); |
| 397 | } |
| 398 | |
| 399 | bool |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 400 | FaceManager::matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 401 | { |
| 402 | if (filter.hasFaceId() && |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 403 | filter.getFaceId() != static_cast<uint64_t>(face.getId())) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 404 | return false; |
| 405 | } |
| 406 | |
| 407 | if (filter.hasUriScheme() && |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 408 | filter.getUriScheme() != face.getRemoteUri().getScheme() && |
| 409 | filter.getUriScheme() != face.getLocalUri().getScheme()) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 410 | return false; |
| 411 | } |
| 412 | |
| 413 | if (filter.hasRemoteUri() && |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 414 | filter.getRemoteUri() != face.getRemoteUri().toString()) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 415 | return false; |
| 416 | } |
| 417 | |
| 418 | if (filter.hasLocalUri() && |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 419 | filter.getLocalUri() != face.getLocalUri().toString()) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 420 | return false; |
| 421 | } |
| 422 | |
| 423 | if (filter.hasFaceScope() && |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 424 | filter.getFaceScope() != face.getScope()) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 425 | return false; |
| 426 | } |
| 427 | |
| 428 | if (filter.hasFacePersistency() && |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 429 | filter.getFacePersistency() != face.getPersistency()) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 430 | return false; |
| 431 | } |
| 432 | |
| 433 | if (filter.hasLinkType() && |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 434 | filter.getLinkType() != face.getLinkType()) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 435 | return false; |
| 436 | } |
| 437 | |
| 438 | return true; |
| 439 | } |
| 440 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 441 | ndn::nfd::FaceStatus |
| 442 | FaceManager::collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now) |
| 443 | { |
| 444 | ndn::nfd::FaceStatus status; |
| 445 | |
| 446 | collectFaceProperties(face, status); |
| 447 | |
| 448 | time::steady_clock::TimePoint expirationTime = face.getExpirationTime(); |
| 449 | if (expirationTime != time::steady_clock::TimePoint::max()) { |
| 450 | status.setExpirationPeriod(std::max(time::milliseconds(0), |
| 451 | time::duration_cast<time::milliseconds>(expirationTime - now))); |
| 452 | } |
| 453 | |
| 454 | const face::FaceCounters& counters = face.getCounters(); |
| 455 | status.setNInInterests(counters.nInInterests) |
| 456 | .setNOutInterests(counters.nOutInterests) |
| 457 | .setNInDatas(counters.nInData) |
| 458 | .setNOutDatas(counters.nOutData) |
| 459 | .setNInNacks(counters.nInNacks) |
| 460 | .setNOutNacks(counters.nOutNacks) |
| 461 | .setNInBytes(counters.nInBytes) |
| 462 | .setNOutBytes(counters.nOutBytes); |
| 463 | |
| 464 | return status; |
| 465 | } |
| 466 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 467 | template<typename FaceTraits> |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 468 | void |
| 469 | FaceManager::collectFaceProperties(const Face& face, FaceTraits& traits) |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 470 | { |
| 471 | traits.setFaceId(face.getId()) |
| 472 | .setRemoteUri(face.getRemoteUri().toString()) |
| 473 | .setLocalUri(face.getLocalUri().toString()) |
| 474 | .setFaceScope(face.getScope()) |
| 475 | .setFacePersistency(face.getPersistency()) |
| 476 | .setLinkType(face.getLinkType()); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 480 | FaceManager::notifyAddFace(const Face& face) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 481 | { |
| 482 | ndn::nfd::FaceEventNotification notification; |
| 483 | notification.setKind(ndn::nfd::FACE_EVENT_CREATED); |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 484 | collectFaceProperties(face, notification); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 485 | |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 486 | m_postNotification(notification.wireEncode()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | void |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 490 | FaceManager::notifyRemoveFace(const Face& face) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 491 | { |
| 492 | ndn::nfd::FaceEventNotification notification; |
| 493 | notification.setKind(ndn::nfd::FACE_EVENT_DESTROYED); |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 494 | collectFaceProperties(face, notification); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 495 | |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 496 | m_postNotification(notification.wireEncode()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void |
| 500 | FaceManager::processConfig(const ConfigSection& configSection, |
| 501 | bool isDryRun, |
| 502 | const std::string& filename) |
| 503 | { |
| 504 | bool hasSeenUnix = false; |
| 505 | bool hasSeenTcp = false; |
| 506 | bool hasSeenUdp = false; |
| 507 | bool hasSeenEther = false; |
| 508 | bool hasSeenWebSocket = false; |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 509 | auto nicList = listNetworkInterfaces(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 510 | |
| 511 | for (const auto& item : configSection) { |
| 512 | if (item.first == "unix") { |
| 513 | if (hasSeenUnix) { |
| 514 | BOOST_THROW_EXCEPTION(Error("Duplicate \"unix\" section")); |
| 515 | } |
| 516 | hasSeenUnix = true; |
| 517 | |
| 518 | processSectionUnix(item.second, isDryRun); |
| 519 | } |
| 520 | else if (item.first == "tcp") { |
| 521 | if (hasSeenTcp) { |
| 522 | BOOST_THROW_EXCEPTION(Error("Duplicate \"tcp\" section")); |
| 523 | } |
| 524 | hasSeenTcp = true; |
| 525 | |
| 526 | processSectionTcp(item.second, isDryRun); |
| 527 | } |
| 528 | else if (item.first == "udp") { |
| 529 | if (hasSeenUdp) { |
| 530 | BOOST_THROW_EXCEPTION(Error("Duplicate \"udp\" section")); |
| 531 | } |
| 532 | hasSeenUdp = true; |
| 533 | |
| 534 | processSectionUdp(item.second, isDryRun, nicList); |
| 535 | } |
| 536 | else if (item.first == "ether") { |
| 537 | if (hasSeenEther) { |
| 538 | BOOST_THROW_EXCEPTION(Error("Duplicate \"ether\" section")); |
| 539 | } |
| 540 | hasSeenEther = true; |
| 541 | |
| 542 | processSectionEther(item.second, isDryRun, nicList); |
| 543 | } |
| 544 | else if (item.first == "websocket") { |
| 545 | if (hasSeenWebSocket) { |
| 546 | BOOST_THROW_EXCEPTION(Error("Duplicate \"websocket\" section")); |
| 547 | } |
| 548 | hasSeenWebSocket = true; |
| 549 | |
| 550 | processSectionWebSocket(item.second, isDryRun); |
| 551 | } |
| 552 | else { |
| 553 | BOOST_THROW_EXCEPTION(Error("Unrecognized option \"" + item.first + "\"")); |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | void |
| 559 | FaceManager::processSectionUnix(const ConfigSection& configSection, bool isDryRun) |
| 560 | { |
| 561 | // ; the unix section contains settings of Unix stream faces and channels |
| 562 | // unix |
| 563 | // { |
| 564 | // path /var/run/nfd.sock ; Unix stream listener path |
| 565 | // } |
| 566 | |
| 567 | #if defined(HAVE_UNIX_SOCKETS) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 568 | std::string path = "/var/run/nfd.sock"; |
| 569 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 570 | for (const auto& i : configSection) { |
| 571 | if (i.first == "path") { |
| 572 | path = i.second.get_value<std::string>(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 573 | } |
| 574 | else { |
| 575 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 576 | i.first + "\" in \"unix\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
| 580 | if (!isDryRun) { |
| 581 | if (m_factories.count("unix") > 0) { |
| 582 | return; |
| 583 | } |
| 584 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 585 | auto factory = make_shared<UnixStreamFactory>(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 586 | m_factories.insert(std::make_pair("unix", factory)); |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 587 | |
| 588 | auto channel = factory->createChannel(path); |
| 589 | channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 590 | } |
| 591 | #else |
| 592 | BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without Unix sockets support, " |
| 593 | "cannot process \"unix\" section")); |
| 594 | #endif // HAVE_UNIX_SOCKETS |
| 595 | } |
| 596 | |
| 597 | void |
| 598 | FaceManager::processSectionTcp(const ConfigSection& configSection, bool isDryRun) |
| 599 | { |
| 600 | // ; the tcp section contains settings of TCP faces and channels |
| 601 | // tcp |
| 602 | // { |
| 603 | // listen yes ; set to 'no' to disable TCP listener, default 'yes' |
| 604 | // port 6363 ; TCP listener port number |
| 605 | // } |
| 606 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 607 | uint16_t port = 6363; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 608 | bool needToListen = true; |
| 609 | bool enableV4 = true; |
| 610 | bool enableV6 = true; |
| 611 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 612 | for (const auto& i : configSection) { |
| 613 | if (i.first == "port") { |
| 614 | port = ConfigFile::parseNumber<uint16_t>(i, "tcp"); |
| 615 | NFD_LOG_TRACE("TCP port set to " << port); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 616 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 617 | else if (i.first == "listen") { |
| 618 | needToListen = ConfigFile::parseYesNo(i, "tcp"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 619 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 620 | else if (i.first == "enable_v4") { |
| 621 | enableV4 = ConfigFile::parseYesNo(i, "tcp"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 622 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 623 | else if (i.first == "enable_v6") { |
| 624 | enableV6 = ConfigFile::parseYesNo(i, "tcp"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 625 | } |
| 626 | else { |
| 627 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 628 | i.first + "\" in \"tcp\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
| 632 | if (!enableV4 && !enableV6) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 633 | BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 TCP channels have been disabled." |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 634 | " Remove \"tcp\" section to disable TCP channels or" |
| 635 | " re-enable at least one channel type.")); |
| 636 | } |
| 637 | |
| 638 | if (!isDryRun) { |
| 639 | if (m_factories.count("tcp") > 0) { |
| 640 | return; |
| 641 | } |
| 642 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 643 | auto factory = make_shared<TcpFactory>(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 644 | m_factories.insert(std::make_pair("tcp", factory)); |
| 645 | |
| 646 | if (enableV4) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 647 | tcp::Endpoint endpoint(boost::asio::ip::tcp::v4(), port); |
| 648 | shared_ptr<TcpChannel> v4Channel = factory->createChannel(endpoint); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 649 | if (needToListen) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 650 | v4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | m_factories.insert(std::make_pair("tcp4", factory)); |
| 654 | } |
| 655 | |
| 656 | if (enableV6) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 657 | tcp::Endpoint endpoint(boost::asio::ip::tcp::v6(), port); |
| 658 | shared_ptr<TcpChannel> v6Channel = factory->createChannel(endpoint); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 659 | if (needToListen) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 660 | v6Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | m_factories.insert(std::make_pair("tcp6", factory)); |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | void |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 669 | FaceManager::processSectionUdp(const ConfigSection& configSection, bool isDryRun, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 670 | const std::vector<NetworkInterfaceInfo>& nicList) |
| 671 | { |
| 672 | // ; the udp section contains settings of UDP faces and channels |
| 673 | // udp |
| 674 | // { |
| 675 | // port 6363 ; UDP unicast port number |
| 676 | // idle_timeout 600 ; idle time (seconds) before closing a UDP unicast face |
| 677 | // keep_alive_interval 25 ; interval (seconds) between keep-alive refreshes |
| 678 | |
| 679 | // ; NFD creates one UDP multicast face per NIC |
| 680 | // mcast yes ; set to 'no' to disable UDP multicast, default 'yes' |
| 681 | // mcast_port 56363 ; UDP multicast port number |
| 682 | // mcast_group 224.0.23.170 ; UDP multicast group (IPv4 only) |
| 683 | // } |
| 684 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 685 | uint16_t port = 6363; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 686 | bool enableV4 = true; |
| 687 | bool enableV6 = true; |
| 688 | size_t timeout = 600; |
| 689 | size_t keepAliveInterval = 25; |
| 690 | bool useMcast = true; |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 691 | auto mcastGroup = boost::asio::ip::address_v4::from_string("224.0.23.170"); |
| 692 | uint16_t mcastPort = 56363; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 693 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 694 | for (const auto& i : configSection) { |
| 695 | if (i.first == "port") { |
| 696 | port = ConfigFile::parseNumber<uint16_t>(i, "udp"); |
| 697 | NFD_LOG_TRACE("UDP unicast port set to " << port); |
| 698 | } |
| 699 | else if (i.first == "enable_v4") { |
| 700 | enableV4 = ConfigFile::parseYesNo(i, "udp"); |
| 701 | } |
| 702 | else if (i.first == "enable_v6") { |
| 703 | enableV6 = ConfigFile::parseYesNo(i, "udp"); |
| 704 | } |
| 705 | else if (i.first == "idle_timeout") { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 706 | try { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 707 | timeout = i.second.get_value<size_t>(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 708 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 709 | catch (const boost::property_tree::ptree_bad_data&) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 710 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 711 | i.first + "\" in \"udp\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 712 | } |
| 713 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 714 | else if (i.first == "keep_alive_interval") { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 715 | try { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 716 | keepAliveInterval = i.second.get_value<size_t>(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 717 | /// \todo Make use of keepAliveInterval |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 718 | (void)(keepAliveInterval); |
| 719 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 720 | catch (const boost::property_tree::ptree_bad_data&) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 721 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 722 | i.first + "\" in \"udp\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 723 | } |
| 724 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 725 | else if (i.first == "mcast") { |
| 726 | useMcast = ConfigFile::parseYesNo(i, "udp"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 727 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 728 | else if (i.first == "mcast_port") { |
| 729 | mcastPort = ConfigFile::parseNumber<uint16_t>(i, "udp"); |
| 730 | NFD_LOG_TRACE("UDP multicast port set to " << mcastPort); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 731 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 732 | else if (i.first == "mcast_group") { |
| 733 | boost::system::error_code ec; |
| 734 | mcastGroup = boost::asio::ip::address_v4::from_string(i.second.get_value<std::string>(), ec); |
| 735 | if (ec) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 736 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 737 | i.first + "\" in \"udp\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 738 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 739 | NFD_LOG_TRACE("UDP multicast group set to " << mcastGroup); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 740 | } |
| 741 | else { |
| 742 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 743 | i.first + "\" in \"udp\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | |
| 747 | if (!enableV4 && !enableV6) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 748 | BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 UDP channels have been disabled." |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 749 | " Remove \"udp\" section to disable UDP channels or" |
| 750 | " re-enable at least one channel type.")); |
| 751 | } |
| 752 | else if (useMcast && !enableV4) { |
| 753 | BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 multicast requested, but IPv4 channels" |
| 754 | " have been disabled (conflicting configuration options set)")); |
| 755 | } |
| 756 | |
| 757 | if (!isDryRun) { |
| 758 | shared_ptr<UdpFactory> factory; |
| 759 | bool isReload = false; |
| 760 | if (m_factories.count("udp") > 0) { |
| 761 | isReload = true; |
| 762 | factory = static_pointer_cast<UdpFactory>(m_factories["udp"]); |
| 763 | } |
| 764 | else { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 765 | factory = make_shared<UdpFactory>(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 766 | m_factories.insert(std::make_pair("udp", factory)); |
| 767 | } |
| 768 | |
| 769 | if (!isReload && enableV4) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 770 | udp::Endpoint endpoint(boost::asio::ip::udp::v4(), port); |
| 771 | shared_ptr<UdpChannel> v4Channel = factory->createChannel(endpoint, time::seconds(timeout)); |
| 772 | v4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 773 | |
| 774 | m_factories.insert(std::make_pair("udp4", factory)); |
| 775 | } |
| 776 | |
| 777 | if (!isReload && enableV6) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 778 | udp::Endpoint endpoint(boost::asio::ip::udp::v6(), port); |
| 779 | shared_ptr<UdpChannel> v6Channel = factory->createChannel(endpoint, time::seconds(timeout)); |
| 780 | v6Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 781 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 782 | m_factories.insert(std::make_pair("udp6", factory)); |
| 783 | } |
| 784 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 785 | std::set<shared_ptr<Face>> multicastFacesToRemove; |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 786 | for (const auto& i : factory->getMulticastFaces()) { |
| 787 | multicastFacesToRemove.insert(i.second); |
| 788 | } |
| 789 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 790 | if (useMcast && enableV4) { |
| 791 | std::vector<NetworkInterfaceInfo> ipv4MulticastInterfaces; |
| 792 | for (const auto& nic : nicList) { |
| 793 | if (nic.isUp() && nic.isMulticastCapable() && !nic.ipv4Addresses.empty()) { |
| 794 | ipv4MulticastInterfaces.push_back(nic); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | bool isNicNameNecessary = false; |
| 799 | #if defined(__linux__) |
| 800 | if (ipv4MulticastInterfaces.size() > 1) { |
| 801 | // On Linux if we have more than one MulticastUdpFace |
| 802 | // we need to specify the name of the interface |
| 803 | isNicNameNecessary = true; |
| 804 | } |
| 805 | #endif |
| 806 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 807 | udp::Endpoint mcastEndpoint(mcastGroup, mcastPort); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 808 | for (const auto& nic : ipv4MulticastInterfaces) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 809 | udp::Endpoint localEndpoint(nic.ipv4Addresses[0], mcastPort); |
| 810 | auto newFace = factory->createMulticastFace(localEndpoint, mcastEndpoint, |
Yukai Tu | 0a49d34 | 2015-09-13 12:54:22 +0800 | [diff] [blame] | 811 | isNicNameNecessary ? nic.name : ""); |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 812 | m_faceTable.add(newFace); |
| 813 | multicastFacesToRemove.erase(newFace); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 816 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 817 | for (const auto& face : multicastFacesToRemove) { |
| 818 | face->close(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | void |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 824 | FaceManager::processSectionEther(const ConfigSection& configSection, bool isDryRun, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 825 | const std::vector<NetworkInterfaceInfo>& nicList) |
| 826 | { |
| 827 | // ; the ether section contains settings of Ethernet faces and channels |
| 828 | // ether |
| 829 | // { |
| 830 | // ; NFD creates one Ethernet multicast face per NIC |
| 831 | // mcast yes ; set to 'no' to disable Ethernet multicast, default 'yes' |
| 832 | // mcast_group 01:00:5E:00:17:AA ; Ethernet multicast group |
| 833 | // } |
| 834 | |
| 835 | #if defined(HAVE_LIBPCAP) |
| 836 | bool useMcast = true; |
| 837 | ethernet::Address mcastGroup(ethernet::getDefaultMulticastAddress()); |
| 838 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 839 | for (const auto& i : configSection) { |
| 840 | if (i.first == "mcast") { |
| 841 | useMcast = ConfigFile::parseYesNo(i, "ether"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 842 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 843 | else if (i.first == "mcast_group") { |
| 844 | mcastGroup = ethernet::Address::fromString(i.second.get_value<std::string>()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 845 | if (mcastGroup.isNull()) { |
| 846 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 847 | i.first + "\" in \"ether\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 848 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 849 | NFD_LOG_TRACE("Ethernet multicast group set to " << mcastGroup); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 850 | } |
| 851 | else { |
| 852 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 853 | i.first + "\" in \"ether\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | |
| 857 | if (!isDryRun) { |
| 858 | shared_ptr<EthernetFactory> factory; |
| 859 | if (m_factories.count("ether") > 0) { |
| 860 | factory = static_pointer_cast<EthernetFactory>(m_factories["ether"]); |
| 861 | } |
| 862 | else { |
| 863 | factory = make_shared<EthernetFactory>(); |
| 864 | m_factories.insert(std::make_pair("ether", factory)); |
| 865 | } |
| 866 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 867 | std::set<shared_ptr<Face>> multicastFacesToRemove; |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 868 | for (const auto& i : factory->getMulticastFaces()) { |
| 869 | multicastFacesToRemove.insert(i.second); |
| 870 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 871 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 872 | if (useMcast) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 873 | for (const auto& nic : nicList) { |
| 874 | if (nic.isUp() && nic.isMulticastCapable()) { |
| 875 | try { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 876 | auto newFace = factory->createMulticastFace(nic, mcastGroup); |
| 877 | m_faceTable.add(newFace); |
| 878 | multicastFacesToRemove.erase(newFace); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 879 | } |
| 880 | catch (const EthernetFactory::Error& factoryError) { |
| 881 | NFD_LOG_ERROR(factoryError.what() << ", continuing"); |
| 882 | } |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 883 | catch (const face::EthernetTransport::Error& faceError) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 884 | NFD_LOG_ERROR(faceError.what() << ", continuing"); |
| 885 | } |
| 886 | } |
| 887 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 888 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 889 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 890 | for (const auto& face : multicastFacesToRemove) { |
| 891 | face->close(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | #else |
| 895 | BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without libpcap, cannot process \"ether\" section")); |
| 896 | #endif // HAVE_LIBPCAP |
| 897 | } |
| 898 | |
| 899 | void |
| 900 | FaceManager::processSectionWebSocket(const ConfigSection& configSection, bool isDryRun) |
| 901 | { |
| 902 | // ; the websocket section contains settings of WebSocket faces and channels |
| 903 | // websocket |
| 904 | // { |
| 905 | // listen yes ; set to 'no' to disable WebSocket listener, default 'yes' |
| 906 | // port 9696 ; WebSocket listener port number |
| 907 | // enable_v4 yes ; set to 'no' to disable listening on IPv4 socket, default 'yes' |
| 908 | // enable_v6 yes ; set to 'no' to disable listening on IPv6 socket, default 'yes' |
| 909 | // } |
| 910 | |
| 911 | #if defined(HAVE_WEBSOCKET) |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 912 | uint16_t port = 9696; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 913 | bool needToListen = true; |
| 914 | bool enableV4 = true; |
| 915 | bool enableV6 = true; |
| 916 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 917 | for (const auto& i : configSection) { |
| 918 | if (i.first == "port") { |
| 919 | port = ConfigFile::parseNumber<uint16_t>(i, "websocket"); |
| 920 | NFD_LOG_TRACE("WebSocket port set to " << port); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 921 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 922 | else if (i.first == "listen") { |
| 923 | needToListen = ConfigFile::parseYesNo(i, "websocket"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 924 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 925 | else if (i.first == "enable_v4") { |
| 926 | enableV4 = ConfigFile::parseYesNo(i, "websocket"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 927 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 928 | else if (i.first == "enable_v6") { |
| 929 | enableV6 = ConfigFile::parseYesNo(i, "websocket"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 930 | } |
| 931 | else { |
| 932 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 933 | i.first + "\" in \"websocket\" section")); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
| 937 | if (!enableV4 && !enableV6) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 938 | BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 WebSocket channels have been disabled." |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 939 | " Remove \"websocket\" section to disable WebSocket channels or" |
| 940 | " re-enable at least one channel type.")); |
| 941 | } |
| 942 | |
| 943 | if (!enableV4 && enableV6) { |
| 944 | BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD does not allow pure IPv6 WebSocket channel.")); |
| 945 | } |
| 946 | |
| 947 | if (!isDryRun) { |
| 948 | if (m_factories.count("websocket") > 0) { |
| 949 | return; |
| 950 | } |
| 951 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 952 | auto factory = make_shared<WebSocketFactory>(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 953 | m_factories.insert(std::make_pair("websocket", factory)); |
| 954 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 955 | shared_ptr<WebSocketChannel> channel; |
| 956 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 957 | if (enableV6 && enableV4) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 958 | websocket::Endpoint endpoint(boost::asio::ip::address_v6::any(), port); |
| 959 | channel = factory->createChannel(endpoint); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 960 | |
| 961 | m_factories.insert(std::make_pair("websocket46", factory)); |
| 962 | } |
| 963 | else if (enableV4) { |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 964 | websocket::Endpoint endpoint(boost::asio::ip::address_v4::any(), port); |
| 965 | channel = factory->createChannel(endpoint); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 966 | |
| 967 | m_factories.insert(std::make_pair("websocket4", factory)); |
| 968 | } |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 969 | |
| 970 | if (channel && needToListen) { |
| 971 | channel->listen(bind(&FaceTable::add, &m_faceTable, _1)); |
| 972 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 973 | } |
| 974 | #else |
| 975 | BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without WebSocket, " |
| 976 | "cannot process \"websocket\" section")); |
| 977 | #endif // HAVE_WEBSOCKET |
| 978 | } |
| 979 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 980 | } // namespace nfd |