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