blob: e3e0cb80cf3063291ef698e170eced7470403443 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Lidf846e52016-01-30 21:53:47 -08003 * Copyright (c) 2014-2016, Regents of the University of California,
Yanbiao Li73860e32015-08-19 16:30:16 -07004 * 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 Shi40cb61c2015-09-23 18:36:45 -070029#include "face/generic-link-service.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070030#include "face/tcp-factory.hpp"
31#include "face/udp-factory.hpp"
Yukai Tu0a49d342015-09-13 12:54:22 +080032#include "fw/face-table.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070033
Yanbiao Li73860e32015-08-19 16:30:16 -070034#include <ndn-cxx/management/nfd-channel-status.hpp>
Davide Pesavento1d7e7af2015-10-10 23:54:08 +020035#include <ndn-cxx/management/nfd-face-status.hpp>
Yanbiao Li73860e32015-08-19 16:30:16 -070036#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 Pesavento35120ea2015-11-17 21:13:18 +010044#include "face/ethernet-transport.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070045#endif // HAVE_LIBPCAP
46
47#ifdef HAVE_WEBSOCKET
48#include "face/websocket-factory.hpp"
49#endif // HAVE_WEBSOCKET
50
51namespace nfd {
52
53NFD_LOG_INIT("FaceManager");
54
Junxiao Shiae04d342016-07-19 13:20:22 +000055FaceManager::FaceManager(FaceTable& faceTable, Dispatcher& dispatcher, CommandValidator& validator)
Yanbiao Lidf846e52016-01-30 21:53:47 -080056 : NfdManagerBase(dispatcher, validator, "faces")
Yanbiao Li73860e32015-08-19 16:30:16 -070057 , m_faceTable(faceTable)
58{
59 registerCommandHandler<ndn::nfd::FaceCreateCommand>("create",
60 bind(&FaceManager::createFace, this, _2, _3, _4, _5));
61
62 registerCommandHandler<ndn::nfd::FaceDestroyCommand>("destroy",
63 bind(&FaceManager::destroyFace, this, _2, _3, _4, _5));
64
65 registerCommandHandler<ndn::nfd::FaceEnableLocalControlCommand>("enable-local-control",
66 bind(&FaceManager::enableLocalControl, this, _2, _3, _4, _5));
67
68 registerCommandHandler<ndn::nfd::FaceDisableLocalControlCommand>("disable-local-control",
69 bind(&FaceManager::disableLocalControl, this, _2, _3, _4, _5));
70
71 registerStatusDatasetHandler("list", bind(&FaceManager::listFaces, this, _1, _2, _3));
72 registerStatusDatasetHandler("channels", bind(&FaceManager::listChannels, this, _1, _2, _3));
73 registerStatusDatasetHandler("query", bind(&FaceManager::queryFaces, this, _1, _2, _3));
74
Junxiao Shiae04d342016-07-19 13:20:22 +000075 m_postNotification = registerNotificationStream("events");
76 m_faceAddConn = m_faceTable.afterAdd.connect(bind(&FaceManager::notifyAddFace, this, _1));
77 m_faceRemoveConn = m_faceTable.beforeRemove.connect(bind(&FaceManager::notifyRemoveFace, this, _1));
Yanbiao Li73860e32015-08-19 16:30:16 -070078}
79
80void
81FaceManager::setConfigFile(ConfigFile& configFile)
82{
83 configFile.addSectionHandler("face_system", bind(&FaceManager::processConfig, this, _1, _2, _3));
84}
85
86void
87FaceManager::createFace(const Name& topPrefix, const Interest& interest,
88 const ControlParameters& parameters,
89 const ndn::mgmt::CommandContinuation& done)
90{
91 FaceUri uri;
92 if (!uri.parse(parameters.getUri())) {
93 NFD_LOG_TRACE("failed to parse URI");
94 return done(ControlResponse(400, "Malformed command"));
95 }
96
97 if (!uri.isCanonical()) {
98 NFD_LOG_TRACE("received non-canonical URI");
99 return done(ControlResponse(400, "Non-canonical URI"));
100 }
101
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200102 auto factory = m_factories.find(uri.getScheme());
Yanbiao Li73860e32015-08-19 16:30:16 -0700103 if (factory == m_factories.end()) {
104 return done(ControlResponse(501, "Unsupported protocol"));
105 }
106
107 try {
108 factory->second->createFace(uri,
109 parameters.getFacePersistency(),
110 bind(&FaceManager::afterCreateFaceSuccess,
111 this, parameters, _1, done),
112 bind(&FaceManager::afterCreateFaceFailure,
113 this, _1, done));
114 }
115 catch (const std::runtime_error& error) {
116 std::string errorMessage = "Face creation failed: ";
117 errorMessage += error.what();
118
119 NFD_LOG_ERROR(errorMessage);
120 return done(ControlResponse(500, errorMessage));
121 }
122 catch (const std::logic_error& error) {
123 std::string errorMessage = "Face creation failed: ";
124 errorMessage += error.what();
125
126 NFD_LOG_ERROR(errorMessage);
127 return done(ControlResponse(500, errorMessage));
128 }
129}
130
131void
Yanbiao Li73860e32015-08-19 16:30:16 -0700132FaceManager::afterCreateFaceSuccess(ControlParameters& parameters,
133 const shared_ptr<Face>& newFace,
134 const ndn::mgmt::CommandContinuation& done)
135{
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200136 m_faceTable.add(newFace);
Yanbiao Li73860e32015-08-19 16:30:16 -0700137 parameters.setFaceId(newFace->getId());
138 parameters.setUri(newFace->getRemoteUri().toString());
139 parameters.setFacePersistency(newFace->getPersistency());
140
141 done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
142}
143
144void
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700145FaceManager::destroyFace(const Name& topPrefix, const Interest& interest,
146 const ControlParameters& parameters,
147 const ndn::mgmt::CommandContinuation& done)
148{
Junxiao Shi5b43f9a2016-07-19 13:15:56 +0000149 Face* face = m_faceTable.get(parameters.getFaceId());
150 if (face != nullptr) {
151 face->close();
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700152 }
153
154 done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
155}
156
157void
Yanbiao Li73860e32015-08-19 16:30:16 -0700158FaceManager::afterCreateFaceFailure(const std::string& reason,
159 const ndn::mgmt::CommandContinuation& done)
160{
161 NFD_LOG_DEBUG("Failed to create face: " << reason);
162
163 done(ControlResponse(408, "Failed to create face: " + reason));
164}
165
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700166void
167FaceManager::enableLocalControl(const Name& topPrefix, const Interest& interest,
168 const ControlParameters& parameters,
169 const ndn::mgmt::CommandContinuation& done)
170{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700171 Face* face = findFaceForLocalControl(interest, parameters, done);
172 if (!face) {
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700173 return;
174 }
175
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700176 // TODO#3226 redesign enable-local-control
177 // For now, enable-local-control will enable all local fields in GenericLinkService.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700178 auto service = dynamic_cast<face::GenericLinkService*>(face->getLinkService());
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700179 if (service == nullptr) {
180 return done(ControlResponse(503, "LinkService type not supported"));
181 }
182
183 face::GenericLinkService::Options options = service->getOptions();
184 options.allowLocalFields = true;
185 service->setOptions(options);
186
187 return done(ControlResponse(200, "OK: enable all local fields on GenericLinkService")
188 .setBody(parameters.wireEncode()));
189}
190
191void
192FaceManager::disableLocalControl(const Name& topPrefix, const Interest& interest,
193 const ControlParameters& parameters,
194 const ndn::mgmt::CommandContinuation& done)
195{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700196 Face* face = findFaceForLocalControl(interest, parameters, done);
197 if (!face) {
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700198 return;
199 }
200
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700201 // TODO#3226 redesign disable-local-control
202 // For now, disable-local-control will disable all local fields in GenericLinkService.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700203 auto service = dynamic_cast<face::GenericLinkService*>(face->getLinkService());
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700204 if (service == nullptr) {
205 return done(ControlResponse(503, "LinkService type not supported"));
206 }
207
208 face::GenericLinkService::Options options = service->getOptions();
209 options.allowLocalFields = false;
210 service->setOptions(options);
211
212 return done(ControlResponse(200, "OK: disable all local fields on GenericLinkService")
213 .setBody(parameters.wireEncode()));
214}
215
Junxiao Shicde37ad2015-12-24 01:02:05 -0700216Face*
217FaceManager::findFaceForLocalControl(const Interest& request,
218 const ControlParameters& parameters,
219 const ndn::mgmt::CommandContinuation& done)
Yanbiao Li73860e32015-08-19 16:30:16 -0700220{
Junxiao Shi0de23a22015-12-03 20:07:02 +0000221 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
222 // NDNLPv2 says "application MUST be prepared to receive a packet without IncomingFaceId field",
223 // but it's fine to assert IncomingFaceId is available, because InternalFace lives inside NFD
224 // and is initialized synchronously with IncomingFaceId field enabled.
225 BOOST_ASSERT(incomingFaceIdTag != nullptr);
226
Junxiao Shi5b43f9a2016-07-19 13:15:56 +0000227 Face* face = m_faceTable.get(*incomingFaceIdTag);
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200228 if (face == nullptr) {
Junxiao Shi0de23a22015-12-03 20:07:02 +0000229 NFD_LOG_DEBUG("FaceId " << *incomingFaceIdTag << " not found");
Yanbiao Li73860e32015-08-19 16:30:16 -0700230 done(ControlResponse(410, "Face not found"));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700231 return nullptr;
Yanbiao Li73860e32015-08-19 16:30:16 -0700232 }
233
Junxiao Shicde37ad2015-12-24 01:02:05 -0700234 if (face->getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200235 NFD_LOG_DEBUG("Cannot enable local control on non-local FaceId " << face->getId());
Yanbiao Li73860e32015-08-19 16:30:16 -0700236 done(ControlResponse(412, "Face is non-local"));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700237 return nullptr;
Yanbiao Li73860e32015-08-19 16:30:16 -0700238 }
239
Junxiao Shi5b43f9a2016-07-19 13:15:56 +0000240 return face;
Yanbiao Li73860e32015-08-19 16:30:16 -0700241}
242
243void
244FaceManager::listFaces(const Name& topPrefix, const Interest& interest,
245 ndn::mgmt::StatusDatasetContext& context)
246{
Eric Newberryc64d30a2015-12-26 11:07:27 -0700247 auto now = time::steady_clock::now();
Junxiao Shib84e6742016-07-19 13:16:22 +0000248 for (const Face& face : m_faceTable) {
249 ndn::nfd::FaceStatus status = collectFaceStatus(face, now);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700250 context.append(status.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700251 }
252 context.end();
253}
254
255void
256FaceManager::listChannels(const Name& topPrefix, const Interest& interest,
257 ndn::mgmt::StatusDatasetContext& context)
258{
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200259 std::set<const ProtocolFactory*> seenFactories;
Yanbiao Li73860e32015-08-19 16:30:16 -0700260
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200261 for (const auto& kv : m_factories) {
262 const ProtocolFactory* factory = kv.second.get();
263 bool inserted;
264 std::tie(std::ignore, inserted) = seenFactories.insert(factory);
Yanbiao Li73860e32015-08-19 16:30:16 -0700265
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200266 if (inserted) {
267 for (const auto& channel : factory->getChannels()) {
268 ndn::nfd::ChannelStatus entry;
269 entry.setLocalUri(channel->getUri().toString());
270 context.append(entry.wireEncode());
271 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700272 }
273 }
274
275 context.end();
276}
277
278void
279FaceManager::queryFaces(const Name& topPrefix, const Interest& interest,
280 ndn::mgmt::StatusDatasetContext& context)
281{
282 ndn::nfd::FaceQueryFilter faceFilter;
283 const Name& query = interest.getName();
284 try {
285 faceFilter.wireDecode(query[-1].blockFromValue());
286 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200287 catch (const tlv::Error& e) {
288 NFD_LOG_DEBUG("Malformed query filter: " << e.what());
289 return context.reject(ControlResponse(400, "Malformed filter"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700290 }
291
Eric Newberryc64d30a2015-12-26 11:07:27 -0700292 auto now = time::steady_clock::now();
Junxiao Shib84e6742016-07-19 13:16:22 +0000293 for (const Face& face : m_faceTable) {
294 if (!matchFilter(faceFilter, face)) {
Junxiao Shida93f1f2015-11-11 06:13:16 -0700295 continue;
Yanbiao Li73860e32015-08-19 16:30:16 -0700296 }
Junxiao Shib84e6742016-07-19 13:16:22 +0000297 ndn::nfd::FaceStatus status = collectFaceStatus(face, now);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700298 context.append(status.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700299 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200300
Yanbiao Li73860e32015-08-19 16:30:16 -0700301 context.end();
302}
303
304bool
Junxiao Shib84e6742016-07-19 13:16:22 +0000305FaceManager::matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face)
Yanbiao Li73860e32015-08-19 16:30:16 -0700306{
307 if (filter.hasFaceId() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000308 filter.getFaceId() != static_cast<uint64_t>(face.getId())) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700309 return false;
310 }
311
312 if (filter.hasUriScheme() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000313 filter.getUriScheme() != face.getRemoteUri().getScheme() &&
314 filter.getUriScheme() != face.getLocalUri().getScheme()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700315 return false;
316 }
317
318 if (filter.hasRemoteUri() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000319 filter.getRemoteUri() != face.getRemoteUri().toString()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700320 return false;
321 }
322
323 if (filter.hasLocalUri() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000324 filter.getLocalUri() != face.getLocalUri().toString()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700325 return false;
326 }
327
328 if (filter.hasFaceScope() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000329 filter.getFaceScope() != face.getScope()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700330 return false;
331 }
332
333 if (filter.hasFacePersistency() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000334 filter.getFacePersistency() != face.getPersistency()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700335 return false;
336 }
337
338 if (filter.hasLinkType() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000339 filter.getLinkType() != face.getLinkType()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700340 return false;
341 }
342
343 return true;
344}
345
Eric Newberryc64d30a2015-12-26 11:07:27 -0700346ndn::nfd::FaceStatus
347FaceManager::collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now)
348{
349 ndn::nfd::FaceStatus status;
350
351 collectFaceProperties(face, status);
352
353 time::steady_clock::TimePoint expirationTime = face.getExpirationTime();
354 if (expirationTime != time::steady_clock::TimePoint::max()) {
355 status.setExpirationPeriod(std::max(time::milliseconds(0),
356 time::duration_cast<time::milliseconds>(expirationTime - now)));
357 }
358
359 const face::FaceCounters& counters = face.getCounters();
360 status.setNInInterests(counters.nInInterests)
361 .setNOutInterests(counters.nOutInterests)
362 .setNInDatas(counters.nInData)
363 .setNOutDatas(counters.nOutData)
364 .setNInNacks(counters.nInNacks)
365 .setNOutNacks(counters.nOutNacks)
366 .setNInBytes(counters.nInBytes)
367 .setNOutBytes(counters.nOutBytes);
368
369 return status;
370}
371
Junxiao Shida93f1f2015-11-11 06:13:16 -0700372template<typename FaceTraits>
Junxiao Shicde37ad2015-12-24 01:02:05 -0700373void
374FaceManager::collectFaceProperties(const Face& face, FaceTraits& traits)
Junxiao Shida93f1f2015-11-11 06:13:16 -0700375{
376 traits.setFaceId(face.getId())
377 .setRemoteUri(face.getRemoteUri().toString())
378 .setLocalUri(face.getLocalUri().toString())
379 .setFaceScope(face.getScope())
380 .setFacePersistency(face.getPersistency())
381 .setLinkType(face.getLinkType());
Junxiao Shida93f1f2015-11-11 06:13:16 -0700382}
383
384void
Junxiao Shiae04d342016-07-19 13:20:22 +0000385FaceManager::notifyAddFace(const Face& face)
Yanbiao Li73860e32015-08-19 16:30:16 -0700386{
387 ndn::nfd::FaceEventNotification notification;
388 notification.setKind(ndn::nfd::FACE_EVENT_CREATED);
Junxiao Shiae04d342016-07-19 13:20:22 +0000389 collectFaceProperties(face, notification);
Yanbiao Li73860e32015-08-19 16:30:16 -0700390
Junxiao Shiae04d342016-07-19 13:20:22 +0000391 m_postNotification(notification.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700392}
393
394void
Junxiao Shiae04d342016-07-19 13:20:22 +0000395FaceManager::notifyRemoveFace(const Face& face)
Yanbiao Li73860e32015-08-19 16:30:16 -0700396{
397 ndn::nfd::FaceEventNotification notification;
398 notification.setKind(ndn::nfd::FACE_EVENT_DESTROYED);
Junxiao Shiae04d342016-07-19 13:20:22 +0000399 collectFaceProperties(face, notification);
Yanbiao Li73860e32015-08-19 16:30:16 -0700400
Junxiao Shiae04d342016-07-19 13:20:22 +0000401 m_postNotification(notification.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700402}
403
404void
405FaceManager::processConfig(const ConfigSection& configSection,
406 bool isDryRun,
407 const std::string& filename)
408{
409 bool hasSeenUnix = false;
410 bool hasSeenTcp = false;
411 bool hasSeenUdp = false;
412 bool hasSeenEther = false;
413 bool hasSeenWebSocket = false;
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200414 auto nicList = listNetworkInterfaces();
Yanbiao Li73860e32015-08-19 16:30:16 -0700415
416 for (const auto& item : configSection) {
417 if (item.first == "unix") {
418 if (hasSeenUnix) {
419 BOOST_THROW_EXCEPTION(Error("Duplicate \"unix\" section"));
420 }
421 hasSeenUnix = true;
422
423 processSectionUnix(item.second, isDryRun);
424 }
425 else if (item.first == "tcp") {
426 if (hasSeenTcp) {
427 BOOST_THROW_EXCEPTION(Error("Duplicate \"tcp\" section"));
428 }
429 hasSeenTcp = true;
430
431 processSectionTcp(item.second, isDryRun);
432 }
433 else if (item.first == "udp") {
434 if (hasSeenUdp) {
435 BOOST_THROW_EXCEPTION(Error("Duplicate \"udp\" section"));
436 }
437 hasSeenUdp = true;
438
439 processSectionUdp(item.second, isDryRun, nicList);
440 }
441 else if (item.first == "ether") {
442 if (hasSeenEther) {
443 BOOST_THROW_EXCEPTION(Error("Duplicate \"ether\" section"));
444 }
445 hasSeenEther = true;
446
447 processSectionEther(item.second, isDryRun, nicList);
448 }
449 else if (item.first == "websocket") {
450 if (hasSeenWebSocket) {
451 BOOST_THROW_EXCEPTION(Error("Duplicate \"websocket\" section"));
452 }
453 hasSeenWebSocket = true;
454
455 processSectionWebSocket(item.second, isDryRun);
456 }
457 else {
458 BOOST_THROW_EXCEPTION(Error("Unrecognized option \"" + item.first + "\""));
459 }
460 }
461}
462
463void
464FaceManager::processSectionUnix(const ConfigSection& configSection, bool isDryRun)
465{
466 // ; the unix section contains settings of Unix stream faces and channels
467 // unix
468 // {
469 // path /var/run/nfd.sock ; Unix stream listener path
470 // }
471
472#if defined(HAVE_UNIX_SOCKETS)
Yanbiao Li73860e32015-08-19 16:30:16 -0700473 std::string path = "/var/run/nfd.sock";
474
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200475 for (const auto& i : configSection) {
476 if (i.first == "path") {
477 path = i.second.get_value<std::string>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700478 }
479 else {
480 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200481 i.first + "\" in \"unix\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700482 }
483 }
484
485 if (!isDryRun) {
486 if (m_factories.count("unix") > 0) {
487 return;
488 }
489
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200490 auto factory = make_shared<UnixStreamFactory>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700491 m_factories.insert(std::make_pair("unix", factory));
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200492
493 auto channel = factory->createChannel(path);
494 channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700495 }
496#else
497 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without Unix sockets support, "
498 "cannot process \"unix\" section"));
499#endif // HAVE_UNIX_SOCKETS
500}
501
502void
503FaceManager::processSectionTcp(const ConfigSection& configSection, bool isDryRun)
504{
505 // ; the tcp section contains settings of TCP faces and channels
506 // tcp
507 // {
508 // listen yes ; set to 'no' to disable TCP listener, default 'yes'
509 // port 6363 ; TCP listener port number
510 // }
511
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200512 uint16_t port = 6363;
Yanbiao Li73860e32015-08-19 16:30:16 -0700513 bool needToListen = true;
514 bool enableV4 = true;
515 bool enableV6 = true;
516
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200517 for (const auto& i : configSection) {
518 if (i.first == "port") {
519 port = ConfigFile::parseNumber<uint16_t>(i, "tcp");
520 NFD_LOG_TRACE("TCP port set to " << port);
Yanbiao Li73860e32015-08-19 16:30:16 -0700521 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200522 else if (i.first == "listen") {
523 needToListen = ConfigFile::parseYesNo(i, "tcp");
Yanbiao Li73860e32015-08-19 16:30:16 -0700524 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200525 else if (i.first == "enable_v4") {
526 enableV4 = ConfigFile::parseYesNo(i, "tcp");
Yanbiao Li73860e32015-08-19 16:30:16 -0700527 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200528 else if (i.first == "enable_v6") {
529 enableV6 = ConfigFile::parseYesNo(i, "tcp");
Yanbiao Li73860e32015-08-19 16:30:16 -0700530 }
531 else {
532 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200533 i.first + "\" in \"tcp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700534 }
535 }
536
537 if (!enableV4 && !enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200538 BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 TCP channels have been disabled."
Yanbiao Li73860e32015-08-19 16:30:16 -0700539 " Remove \"tcp\" section to disable TCP channels or"
540 " re-enable at least one channel type."));
541 }
542
543 if (!isDryRun) {
544 if (m_factories.count("tcp") > 0) {
545 return;
546 }
547
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200548 auto factory = make_shared<TcpFactory>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700549 m_factories.insert(std::make_pair("tcp", factory));
550
551 if (enableV4) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200552 tcp::Endpoint endpoint(boost::asio::ip::tcp::v4(), port);
553 shared_ptr<TcpChannel> v4Channel = factory->createChannel(endpoint);
Yanbiao Li73860e32015-08-19 16:30:16 -0700554 if (needToListen) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200555 v4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700556 }
557
558 m_factories.insert(std::make_pair("tcp4", factory));
559 }
560
561 if (enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200562 tcp::Endpoint endpoint(boost::asio::ip::tcp::v6(), port);
563 shared_ptr<TcpChannel> v6Channel = factory->createChannel(endpoint);
Yanbiao Li73860e32015-08-19 16:30:16 -0700564 if (needToListen) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200565 v6Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700566 }
567
568 m_factories.insert(std::make_pair("tcp6", factory));
569 }
570 }
571}
572
573void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200574FaceManager::processSectionUdp(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700575 const std::vector<NetworkInterfaceInfo>& nicList)
576{
577 // ; the udp section contains settings of UDP faces and channels
578 // udp
579 // {
580 // port 6363 ; UDP unicast port number
581 // idle_timeout 600 ; idle time (seconds) before closing a UDP unicast face
582 // keep_alive_interval 25 ; interval (seconds) between keep-alive refreshes
583
584 // ; NFD creates one UDP multicast face per NIC
585 // mcast yes ; set to 'no' to disable UDP multicast, default 'yes'
586 // mcast_port 56363 ; UDP multicast port number
587 // mcast_group 224.0.23.170 ; UDP multicast group (IPv4 only)
588 // }
589
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200590 uint16_t port = 6363;
Yanbiao Li73860e32015-08-19 16:30:16 -0700591 bool enableV4 = true;
592 bool enableV6 = true;
593 size_t timeout = 600;
594 size_t keepAliveInterval = 25;
595 bool useMcast = true;
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200596 auto mcastGroup = boost::asio::ip::address_v4::from_string("224.0.23.170");
597 uint16_t mcastPort = 56363;
Yanbiao Li73860e32015-08-19 16:30:16 -0700598
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200599 for (const auto& i : configSection) {
600 if (i.first == "port") {
601 port = ConfigFile::parseNumber<uint16_t>(i, "udp");
602 NFD_LOG_TRACE("UDP unicast port set to " << port);
603 }
604 else if (i.first == "enable_v4") {
605 enableV4 = ConfigFile::parseYesNo(i, "udp");
606 }
607 else if (i.first == "enable_v6") {
608 enableV6 = ConfigFile::parseYesNo(i, "udp");
609 }
610 else if (i.first == "idle_timeout") {
Yanbiao Li73860e32015-08-19 16:30:16 -0700611 try {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200612 timeout = i.second.get_value<size_t>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700613 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200614 catch (const boost::property_tree::ptree_bad_data&) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700615 BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200616 i.first + "\" in \"udp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700617 }
618 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200619 else if (i.first == "keep_alive_interval") {
Yanbiao Li73860e32015-08-19 16:30:16 -0700620 try {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200621 keepAliveInterval = i.second.get_value<size_t>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700622 /// \todo Make use of keepAliveInterval
Yanbiao Li73860e32015-08-19 16:30:16 -0700623 (void)(keepAliveInterval);
624 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200625 catch (const boost::property_tree::ptree_bad_data&) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700626 BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200627 i.first + "\" in \"udp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700628 }
629 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200630 else if (i.first == "mcast") {
631 useMcast = ConfigFile::parseYesNo(i, "udp");
Yanbiao Li73860e32015-08-19 16:30:16 -0700632 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200633 else if (i.first == "mcast_port") {
634 mcastPort = ConfigFile::parseNumber<uint16_t>(i, "udp");
635 NFD_LOG_TRACE("UDP multicast port set to " << mcastPort);
Yanbiao Li73860e32015-08-19 16:30:16 -0700636 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200637 else if (i.first == "mcast_group") {
638 boost::system::error_code ec;
639 mcastGroup = boost::asio::ip::address_v4::from_string(i.second.get_value<std::string>(), ec);
640 if (ec) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700641 BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200642 i.first + "\" in \"udp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700643 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200644 NFD_LOG_TRACE("UDP multicast group set to " << mcastGroup);
Yanbiao Li73860e32015-08-19 16:30:16 -0700645 }
646 else {
647 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200648 i.first + "\" in \"udp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700649 }
650 }
651
652 if (!enableV4 && !enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200653 BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 UDP channels have been disabled."
Yanbiao Li73860e32015-08-19 16:30:16 -0700654 " Remove \"udp\" section to disable UDP channels or"
655 " re-enable at least one channel type."));
656 }
657 else if (useMcast && !enableV4) {
658 BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 multicast requested, but IPv4 channels"
659 " have been disabled (conflicting configuration options set)"));
660 }
661
662 if (!isDryRun) {
663 shared_ptr<UdpFactory> factory;
664 bool isReload = false;
665 if (m_factories.count("udp") > 0) {
666 isReload = true;
667 factory = static_pointer_cast<UdpFactory>(m_factories["udp"]);
668 }
669 else {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200670 factory = make_shared<UdpFactory>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700671 m_factories.insert(std::make_pair("udp", factory));
672 }
673
674 if (!isReload && enableV4) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200675 udp::Endpoint endpoint(boost::asio::ip::udp::v4(), port);
676 shared_ptr<UdpChannel> v4Channel = factory->createChannel(endpoint, time::seconds(timeout));
677 v4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700678
679 m_factories.insert(std::make_pair("udp4", factory));
680 }
681
682 if (!isReload && enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200683 udp::Endpoint endpoint(boost::asio::ip::udp::v6(), port);
684 shared_ptr<UdpChannel> v6Channel = factory->createChannel(endpoint, time::seconds(timeout));
685 v6Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700686
Yanbiao Li73860e32015-08-19 16:30:16 -0700687 m_factories.insert(std::make_pair("udp6", factory));
688 }
689
Junxiao Shicde37ad2015-12-24 01:02:05 -0700690 std::set<shared_ptr<Face>> multicastFacesToRemove;
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200691 for (const auto& i : factory->getMulticastFaces()) {
692 multicastFacesToRemove.insert(i.second);
693 }
694
Yanbiao Li73860e32015-08-19 16:30:16 -0700695 if (useMcast && enableV4) {
696 std::vector<NetworkInterfaceInfo> ipv4MulticastInterfaces;
697 for (const auto& nic : nicList) {
698 if (nic.isUp() && nic.isMulticastCapable() && !nic.ipv4Addresses.empty()) {
699 ipv4MulticastInterfaces.push_back(nic);
700 }
701 }
702
703 bool isNicNameNecessary = false;
704#if defined(__linux__)
705 if (ipv4MulticastInterfaces.size() > 1) {
706 // On Linux if we have more than one MulticastUdpFace
707 // we need to specify the name of the interface
708 isNicNameNecessary = true;
709 }
710#endif
711
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200712 udp::Endpoint mcastEndpoint(mcastGroup, mcastPort);
Yanbiao Li73860e32015-08-19 16:30:16 -0700713 for (const auto& nic : ipv4MulticastInterfaces) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200714 udp::Endpoint localEndpoint(nic.ipv4Addresses[0], mcastPort);
715 auto newFace = factory->createMulticastFace(localEndpoint, mcastEndpoint,
Yukai Tu0a49d342015-09-13 12:54:22 +0800716 isNicNameNecessary ? nic.name : "");
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200717 m_faceTable.add(newFace);
718 multicastFacesToRemove.erase(newFace);
Yanbiao Li73860e32015-08-19 16:30:16 -0700719 }
720 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700721
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200722 for (const auto& face : multicastFacesToRemove) {
723 face->close();
Yanbiao Li73860e32015-08-19 16:30:16 -0700724 }
725 }
726}
727
728void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200729FaceManager::processSectionEther(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700730 const std::vector<NetworkInterfaceInfo>& nicList)
731{
732 // ; the ether section contains settings of Ethernet faces and channels
733 // ether
734 // {
735 // ; NFD creates one Ethernet multicast face per NIC
736 // mcast yes ; set to 'no' to disable Ethernet multicast, default 'yes'
737 // mcast_group 01:00:5E:00:17:AA ; Ethernet multicast group
738 // }
739
740#if defined(HAVE_LIBPCAP)
741 bool useMcast = true;
742 ethernet::Address mcastGroup(ethernet::getDefaultMulticastAddress());
743
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200744 for (const auto& i : configSection) {
745 if (i.first == "mcast") {
746 useMcast = ConfigFile::parseYesNo(i, "ether");
Yanbiao Li73860e32015-08-19 16:30:16 -0700747 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200748 else if (i.first == "mcast_group") {
749 mcastGroup = ethernet::Address::fromString(i.second.get_value<std::string>());
Yanbiao Li73860e32015-08-19 16:30:16 -0700750 if (mcastGroup.isNull()) {
751 BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200752 i.first + "\" in \"ether\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700753 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200754 NFD_LOG_TRACE("Ethernet multicast group set to " << mcastGroup);
Yanbiao Li73860e32015-08-19 16:30:16 -0700755 }
756 else {
757 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200758 i.first + "\" in \"ether\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700759 }
760 }
761
762 if (!isDryRun) {
763 shared_ptr<EthernetFactory> factory;
764 if (m_factories.count("ether") > 0) {
765 factory = static_pointer_cast<EthernetFactory>(m_factories["ether"]);
766 }
767 else {
768 factory = make_shared<EthernetFactory>();
769 m_factories.insert(std::make_pair("ether", factory));
770 }
771
Junxiao Shicde37ad2015-12-24 01:02:05 -0700772 std::set<shared_ptr<Face>> multicastFacesToRemove;
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200773 for (const auto& i : factory->getMulticastFaces()) {
774 multicastFacesToRemove.insert(i.second);
775 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700776
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200777 if (useMcast) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700778 for (const auto& nic : nicList) {
779 if (nic.isUp() && nic.isMulticastCapable()) {
780 try {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200781 auto newFace = factory->createMulticastFace(nic, mcastGroup);
782 m_faceTable.add(newFace);
783 multicastFacesToRemove.erase(newFace);
Yanbiao Li73860e32015-08-19 16:30:16 -0700784 }
785 catch (const EthernetFactory::Error& factoryError) {
786 NFD_LOG_ERROR(factoryError.what() << ", continuing");
787 }
Davide Pesavento35120ea2015-11-17 21:13:18 +0100788 catch (const face::EthernetTransport::Error& faceError) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700789 NFD_LOG_ERROR(faceError.what() << ", continuing");
790 }
791 }
792 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700793 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700794
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200795 for (const auto& face : multicastFacesToRemove) {
796 face->close();
Yanbiao Li73860e32015-08-19 16:30:16 -0700797 }
798 }
799#else
800 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without libpcap, cannot process \"ether\" section"));
801#endif // HAVE_LIBPCAP
802}
803
804void
805FaceManager::processSectionWebSocket(const ConfigSection& configSection, bool isDryRun)
806{
807 // ; the websocket section contains settings of WebSocket faces and channels
808 // websocket
809 // {
810 // listen yes ; set to 'no' to disable WebSocket listener, default 'yes'
811 // port 9696 ; WebSocket listener port number
812 // enable_v4 yes ; set to 'no' to disable listening on IPv4 socket, default 'yes'
813 // enable_v6 yes ; set to 'no' to disable listening on IPv6 socket, default 'yes'
814 // }
815
816#if defined(HAVE_WEBSOCKET)
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200817 uint16_t port = 9696;
Yanbiao Li73860e32015-08-19 16:30:16 -0700818 bool needToListen = true;
819 bool enableV4 = true;
820 bool enableV6 = true;
821
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200822 for (const auto& i : configSection) {
823 if (i.first == "port") {
824 port = ConfigFile::parseNumber<uint16_t>(i, "websocket");
825 NFD_LOG_TRACE("WebSocket port set to " << port);
Yanbiao Li73860e32015-08-19 16:30:16 -0700826 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200827 else if (i.first == "listen") {
828 needToListen = ConfigFile::parseYesNo(i, "websocket");
Yanbiao Li73860e32015-08-19 16:30:16 -0700829 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200830 else if (i.first == "enable_v4") {
831 enableV4 = ConfigFile::parseYesNo(i, "websocket");
Yanbiao Li73860e32015-08-19 16:30:16 -0700832 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200833 else if (i.first == "enable_v6") {
834 enableV6 = ConfigFile::parseYesNo(i, "websocket");
Yanbiao Li73860e32015-08-19 16:30:16 -0700835 }
836 else {
837 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200838 i.first + "\" in \"websocket\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700839 }
840 }
841
842 if (!enableV4 && !enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200843 BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 WebSocket channels have been disabled."
Yanbiao Li73860e32015-08-19 16:30:16 -0700844 " Remove \"websocket\" section to disable WebSocket channels or"
845 " re-enable at least one channel type."));
846 }
847
848 if (!enableV4 && enableV6) {
849 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD does not allow pure IPv6 WebSocket channel."));
850 }
851
852 if (!isDryRun) {
853 if (m_factories.count("websocket") > 0) {
854 return;
855 }
856
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200857 auto factory = make_shared<WebSocketFactory>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700858 m_factories.insert(std::make_pair("websocket", factory));
859
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200860 shared_ptr<WebSocketChannel> channel;
861
Yanbiao Li73860e32015-08-19 16:30:16 -0700862 if (enableV6 && enableV4) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200863 websocket::Endpoint endpoint(boost::asio::ip::address_v6::any(), port);
864 channel = factory->createChannel(endpoint);
Yanbiao Li73860e32015-08-19 16:30:16 -0700865
866 m_factories.insert(std::make_pair("websocket46", factory));
867 }
868 else if (enableV4) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200869 websocket::Endpoint endpoint(boost::asio::ip::address_v4::any(), port);
870 channel = factory->createChannel(endpoint);
Yanbiao Li73860e32015-08-19 16:30:16 -0700871
872 m_factories.insert(std::make_pair("websocket4", factory));
873 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200874
875 if (channel && needToListen) {
876 channel->listen(bind(&FaceTable::add, &m_faceTable, _1));
877 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700878 }
879#else
880 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without WebSocket, "
881 "cannot process \"websocket\" section"));
882#endif // HAVE_WEBSOCKET
883}
884
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200885} // namespace nfd