blob: 2263a7d2603fee2e7978eb1dbb6139d3b2b125f0 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
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 Shi40cb61c2015-09-23 18:36:45 -070029#include "face/generic-link-service.hpp"
Alexander Afanasyev9f5f1452016-09-08 15:22:46 -070030
31#include "face/protocol-factory.hpp"
32
33#ifdef HAVE_TCP
Yanbiao Li73860e32015-08-19 16:30:16 -070034#include "face/tcp-factory.hpp"
Alexander Afanasyev9f5f1452016-09-08 15:22:46 -070035#endif // HAVE_TCP
36
37#ifdef HAVE_UDP
Yanbiao Li73860e32015-08-19 16:30:16 -070038#include "face/udp-factory.hpp"
Alexander Afanasyev9f5f1452016-09-08 15:22:46 -070039#endif // HAVE_UDP
40
Yukai Tu0a49d342015-09-13 12:54:22 +080041#include "fw/face-table.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070042
Yanbiao Li73860e32015-08-19 16:30:16 -070043#include <ndn-cxx/management/nfd-channel-status.hpp>
Davide Pesavento1d7e7af2015-10-10 23:54:08 +020044#include <ndn-cxx/management/nfd-face-status.hpp>
Yanbiao Li73860e32015-08-19 16:30:16 -070045#include <ndn-cxx/management/nfd-face-event-notification.hpp>
46
47#ifdef HAVE_UNIX_SOCKETS
48#include "face/unix-stream-factory.hpp"
49#endif // HAVE_UNIX_SOCKETS
50
51#ifdef HAVE_LIBPCAP
52#include "face/ethernet-factory.hpp"
Davide Pesavento35120ea2015-11-17 21:13:18 +010053#include "face/ethernet-transport.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070054#endif // HAVE_LIBPCAP
55
56#ifdef HAVE_WEBSOCKET
57#include "face/websocket-factory.hpp"
58#endif // HAVE_WEBSOCKET
59
60namespace nfd {
61
62NFD_LOG_INIT("FaceManager");
63
64FaceManager::FaceManager(FaceTable& faceTable,
65 Dispatcher& dispatcher,
66 CommandValidator& validator)
67 : ManagerBase(dispatcher, validator, "faces")
68 , m_faceTable(faceTable)
69{
70 registerCommandHandler<ndn::nfd::FaceCreateCommand>("create",
71 bind(&FaceManager::createFace, this, _2, _3, _4, _5));
72
73 registerCommandHandler<ndn::nfd::FaceDestroyCommand>("destroy",
74 bind(&FaceManager::destroyFace, this, _2, _3, _4, _5));
75
76 registerCommandHandler<ndn::nfd::FaceEnableLocalControlCommand>("enable-local-control",
77 bind(&FaceManager::enableLocalControl, this, _2, _3, _4, _5));
78
79 registerCommandHandler<ndn::nfd::FaceDisableLocalControlCommand>("disable-local-control",
80 bind(&FaceManager::disableLocalControl, this, _2, _3, _4, _5));
81
82 registerStatusDatasetHandler("list", bind(&FaceManager::listFaces, this, _1, _2, _3));
83 registerStatusDatasetHandler("channels", bind(&FaceManager::listChannels, this, _1, _2, _3));
84 registerStatusDatasetHandler("query", bind(&FaceManager::queryFaces, this, _1, _2, _3));
85
86 auto postNotification = registerNotificationStream("events");
87 m_faceAddConn =
Junxiao Shicde37ad2015-12-24 01:02:05 -070088 m_faceTable.afterAdd.connect(bind(&FaceManager::afterFaceAdded, this, _1, postNotification));
Yanbiao Li73860e32015-08-19 16:30:16 -070089 m_faceRemoveConn =
Junxiao Shicde37ad2015-12-24 01:02:05 -070090 m_faceTable.beforeRemove.connect(bind(&FaceManager::afterFaceRemoved, this, _1, postNotification));
Yanbiao Li73860e32015-08-19 16:30:16 -070091}
92
93void
94FaceManager::setConfigFile(ConfigFile& configFile)
95{
96 configFile.addSectionHandler("face_system", bind(&FaceManager::processConfig, this, _1, _2, _3));
97}
98
99void
100FaceManager::createFace(const Name& topPrefix, const Interest& interest,
101 const ControlParameters& parameters,
102 const ndn::mgmt::CommandContinuation& done)
103{
104 FaceUri uri;
105 if (!uri.parse(parameters.getUri())) {
106 NFD_LOG_TRACE("failed to parse URI");
107 return done(ControlResponse(400, "Malformed command"));
108 }
109
110 if (!uri.isCanonical()) {
111 NFD_LOG_TRACE("received non-canonical URI");
112 return done(ControlResponse(400, "Non-canonical URI"));
113 }
114
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200115 auto factory = m_factories.find(uri.getScheme());
Yanbiao Li73860e32015-08-19 16:30:16 -0700116 if (factory == m_factories.end()) {
117 return done(ControlResponse(501, "Unsupported protocol"));
118 }
119
120 try {
121 factory->second->createFace(uri,
122 parameters.getFacePersistency(),
123 bind(&FaceManager::afterCreateFaceSuccess,
124 this, parameters, _1, done),
125 bind(&FaceManager::afterCreateFaceFailure,
126 this, _1, done));
127 }
128 catch (const std::runtime_error& error) {
129 std::string errorMessage = "Face creation failed: ";
130 errorMessage += error.what();
131
132 NFD_LOG_ERROR(errorMessage);
133 return done(ControlResponse(500, errorMessage));
134 }
135 catch (const std::logic_error& error) {
136 std::string errorMessage = "Face creation failed: ";
137 errorMessage += error.what();
138
139 NFD_LOG_ERROR(errorMessage);
140 return done(ControlResponse(500, errorMessage));
141 }
142}
143
144void
Yanbiao Li73860e32015-08-19 16:30:16 -0700145FaceManager::afterCreateFaceSuccess(ControlParameters& parameters,
146 const shared_ptr<Face>& newFace,
147 const ndn::mgmt::CommandContinuation& done)
148{
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200149 m_faceTable.add(newFace);
Yanbiao Li73860e32015-08-19 16:30:16 -0700150 parameters.setFaceId(newFace->getId());
151 parameters.setUri(newFace->getRemoteUri().toString());
152 parameters.setFacePersistency(newFace->getPersistency());
153
154 done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
155}
156
157void
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700158FaceManager::destroyFace(const Name& topPrefix, const Interest& interest,
159 const ControlParameters& parameters,
160 const ndn::mgmt::CommandContinuation& done)
161{
162 shared_ptr<Face> target = m_faceTable.get(parameters.getFaceId());
163 if (target) {
164 target->close();
165 }
166
167 done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
168}
169
170void
Yanbiao Li73860e32015-08-19 16:30:16 -0700171FaceManager::afterCreateFaceFailure(const std::string& reason,
172 const ndn::mgmt::CommandContinuation& done)
173{
174 NFD_LOG_DEBUG("Failed to create face: " << reason);
175
176 done(ControlResponse(408, "Failed to create face: " + reason));
177}
178
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700179void
180FaceManager::enableLocalControl(const Name& topPrefix, const Interest& interest,
181 const ControlParameters& parameters,
182 const ndn::mgmt::CommandContinuation& done)
183{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700184 Face* face = findFaceForLocalControl(interest, parameters, done);
185 if (!face) {
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700186 return;
187 }
188
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700189 // TODO#3226 redesign enable-local-control
190 // For now, enable-local-control will enable all local fields in GenericLinkService.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700191 auto service = dynamic_cast<face::GenericLinkService*>(face->getLinkService());
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700192 if (service == nullptr) {
193 return done(ControlResponse(503, "LinkService type not supported"));
194 }
195
196 face::GenericLinkService::Options options = service->getOptions();
197 options.allowLocalFields = true;
198 service->setOptions(options);
199
200 return done(ControlResponse(200, "OK: enable all local fields on GenericLinkService")
201 .setBody(parameters.wireEncode()));
202}
203
204void
205FaceManager::disableLocalControl(const Name& topPrefix, const Interest& interest,
206 const ControlParameters& parameters,
207 const ndn::mgmt::CommandContinuation& done)
208{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700209 Face* face = findFaceForLocalControl(interest, parameters, done);
210 if (!face) {
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700211 return;
212 }
213
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700214 // TODO#3226 redesign disable-local-control
215 // For now, disable-local-control will disable all local fields in GenericLinkService.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700216 auto service = dynamic_cast<face::GenericLinkService*>(face->getLinkService());
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700217 if (service == nullptr) {
218 return done(ControlResponse(503, "LinkService type not supported"));
219 }
220
221 face::GenericLinkService::Options options = service->getOptions();
222 options.allowLocalFields = false;
223 service->setOptions(options);
224
225 return done(ControlResponse(200, "OK: disable all local fields on GenericLinkService")
226 .setBody(parameters.wireEncode()));
227}
228
Junxiao Shicde37ad2015-12-24 01:02:05 -0700229Face*
230FaceManager::findFaceForLocalControl(const Interest& request,
231 const ControlParameters& parameters,
232 const ndn::mgmt::CommandContinuation& done)
Yanbiao Li73860e32015-08-19 16:30:16 -0700233{
Junxiao Shi0de23a22015-12-03 20:07:02 +0000234 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
235 // NDNLPv2 says "application MUST be prepared to receive a packet without IncomingFaceId field",
236 // but it's fine to assert IncomingFaceId is available, because InternalFace lives inside NFD
237 // and is initialized synchronously with IncomingFaceId field enabled.
238 BOOST_ASSERT(incomingFaceIdTag != nullptr);
239
240 auto face = m_faceTable.get(*incomingFaceIdTag);
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200241 if (face == nullptr) {
Junxiao Shi0de23a22015-12-03 20:07:02 +0000242 NFD_LOG_DEBUG("FaceId " << *incomingFaceIdTag << " not found");
Yanbiao Li73860e32015-08-19 16:30:16 -0700243 done(ControlResponse(410, "Face not found"));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700244 return nullptr;
Yanbiao Li73860e32015-08-19 16:30:16 -0700245 }
246
Junxiao Shicde37ad2015-12-24 01:02:05 -0700247 if (face->getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200248 NFD_LOG_DEBUG("Cannot enable local control on non-local FaceId " << face->getId());
Yanbiao Li73860e32015-08-19 16:30:16 -0700249 done(ControlResponse(412, "Face is non-local"));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700250 return nullptr;
Yanbiao Li73860e32015-08-19 16:30:16 -0700251 }
252
Junxiao Shicde37ad2015-12-24 01:02:05 -0700253 return face.get();
Yanbiao Li73860e32015-08-19 16:30:16 -0700254}
255
256void
257FaceManager::listFaces(const Name& topPrefix, const Interest& interest,
258 ndn::mgmt::StatusDatasetContext& context)
259{
Eric Newberryc64d30a2015-12-26 11:07:27 -0700260 auto now = time::steady_clock::now();
Yanbiao Li73860e32015-08-19 16:30:16 -0700261 for (const auto& face : m_faceTable) {
Eric Newberryc64d30a2015-12-26 11:07:27 -0700262 ndn::nfd::FaceStatus status = collectFaceStatus(*face, now);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700263 context.append(status.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700264 }
265 context.end();
266}
267
268void
269FaceManager::listChannels(const Name& topPrefix, const Interest& interest,
270 ndn::mgmt::StatusDatasetContext& context)
271{
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200272 std::set<const ProtocolFactory*> seenFactories;
Yanbiao Li73860e32015-08-19 16:30:16 -0700273
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200274 for (const auto& kv : m_factories) {
275 const ProtocolFactory* factory = kv.second.get();
276 bool inserted;
277 std::tie(std::ignore, inserted) = seenFactories.insert(factory);
Yanbiao Li73860e32015-08-19 16:30:16 -0700278
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200279 if (inserted) {
280 for (const auto& channel : factory->getChannels()) {
281 ndn::nfd::ChannelStatus entry;
282 entry.setLocalUri(channel->getUri().toString());
283 context.append(entry.wireEncode());
284 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700285 }
286 }
287
288 context.end();
289}
290
291void
292FaceManager::queryFaces(const Name& topPrefix, const Interest& interest,
293 ndn::mgmt::StatusDatasetContext& context)
294{
295 ndn::nfd::FaceQueryFilter faceFilter;
296 const Name& query = interest.getName();
297 try {
298 faceFilter.wireDecode(query[-1].blockFromValue());
299 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200300 catch (const tlv::Error& e) {
301 NFD_LOG_DEBUG("Malformed query filter: " << e.what());
302 return context.reject(ControlResponse(400, "Malformed filter"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700303 }
304
Eric Newberryc64d30a2015-12-26 11:07:27 -0700305 auto now = time::steady_clock::now();
Yanbiao Li73860e32015-08-19 16:30:16 -0700306 for (const auto& face : m_faceTable) {
Junxiao Shida93f1f2015-11-11 06:13:16 -0700307 if (!doesMatchFilter(faceFilter, face)) {
308 continue;
Yanbiao Li73860e32015-08-19 16:30:16 -0700309 }
Eric Newberryc64d30a2015-12-26 11:07:27 -0700310 ndn::nfd::FaceStatus status = collectFaceStatus(*face, now);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700311 context.append(status.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700312 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200313
Yanbiao Li73860e32015-08-19 16:30:16 -0700314 context.end();
315}
316
317bool
318FaceManager::doesMatchFilter(const ndn::nfd::FaceQueryFilter& filter, shared_ptr<Face> face)
319{
320 if (filter.hasFaceId() &&
321 filter.getFaceId() != static_cast<uint64_t>(face->getId())) {
322 return false;
323 }
324
325 if (filter.hasUriScheme() &&
326 filter.getUriScheme() != face->getRemoteUri().getScheme() &&
327 filter.getUriScheme() != face->getLocalUri().getScheme()) {
328 return false;
329 }
330
331 if (filter.hasRemoteUri() &&
332 filter.getRemoteUri() != face->getRemoteUri().toString()) {
333 return false;
334 }
335
336 if (filter.hasLocalUri() &&
337 filter.getLocalUri() != face->getLocalUri().toString()) {
338 return false;
339 }
340
341 if (filter.hasFaceScope() &&
Junxiao Shicde37ad2015-12-24 01:02:05 -0700342 filter.getFaceScope() != face->getScope()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700343 return false;
344 }
345
346 if (filter.hasFacePersistency() &&
347 filter.getFacePersistency() != face->getPersistency()) {
348 return false;
349 }
350
351 if (filter.hasLinkType() &&
Junxiao Shicde37ad2015-12-24 01:02:05 -0700352 filter.getLinkType() != face->getLinkType()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700353 return false;
354 }
355
356 return true;
357}
358
Eric Newberryc64d30a2015-12-26 11:07:27 -0700359ndn::nfd::FaceStatus
360FaceManager::collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now)
361{
362 ndn::nfd::FaceStatus status;
363
364 collectFaceProperties(face, status);
365
366 time::steady_clock::TimePoint expirationTime = face.getExpirationTime();
367 if (expirationTime != time::steady_clock::TimePoint::max()) {
368 status.setExpirationPeriod(std::max(time::milliseconds(0),
369 time::duration_cast<time::milliseconds>(expirationTime - now)));
370 }
371
372 const face::FaceCounters& counters = face.getCounters();
373 status.setNInInterests(counters.nInInterests)
374 .setNOutInterests(counters.nOutInterests)
375 .setNInDatas(counters.nInData)
376 .setNOutDatas(counters.nOutData)
377 .setNInNacks(counters.nInNacks)
378 .setNOutNacks(counters.nOutNacks)
379 .setNInBytes(counters.nInBytes)
380 .setNOutBytes(counters.nOutBytes);
381
382 return status;
383}
384
Junxiao Shida93f1f2015-11-11 06:13:16 -0700385template<typename FaceTraits>
Junxiao Shicde37ad2015-12-24 01:02:05 -0700386void
387FaceManager::collectFaceProperties(const Face& face, FaceTraits& traits)
Junxiao Shida93f1f2015-11-11 06:13:16 -0700388{
389 traits.setFaceId(face.getId())
390 .setRemoteUri(face.getRemoteUri().toString())
391 .setLocalUri(face.getLocalUri().toString())
392 .setFaceScope(face.getScope())
393 .setFacePersistency(face.getPersistency())
394 .setLinkType(face.getLinkType());
Junxiao Shida93f1f2015-11-11 06:13:16 -0700395}
396
397void
Yanbiao Li73860e32015-08-19 16:30:16 -0700398FaceManager::afterFaceAdded(shared_ptr<Face> face,
399 const ndn::mgmt::PostNotification& post)
400{
401 ndn::nfd::FaceEventNotification notification;
402 notification.setKind(ndn::nfd::FACE_EVENT_CREATED);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700403 collectFaceProperties(*face, notification);
Yanbiao Li73860e32015-08-19 16:30:16 -0700404
405 post(notification.wireEncode());
406}
407
408void
409FaceManager::afterFaceRemoved(shared_ptr<Face> face,
410 const ndn::mgmt::PostNotification& post)
411{
412 ndn::nfd::FaceEventNotification notification;
413 notification.setKind(ndn::nfd::FACE_EVENT_DESTROYED);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700414 collectFaceProperties(*face, notification);
Yanbiao Li73860e32015-08-19 16:30:16 -0700415
416 post(notification.wireEncode());
417}
418
419void
420FaceManager::processConfig(const ConfigSection& configSection,
421 bool isDryRun,
422 const std::string& filename)
423{
424 bool hasSeenUnix = false;
425 bool hasSeenTcp = false;
426 bool hasSeenUdp = false;
427 bool hasSeenEther = false;
428 bool hasSeenWebSocket = false;
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200429 auto nicList = listNetworkInterfaces();
Yanbiao Li73860e32015-08-19 16:30:16 -0700430
431 for (const auto& item : configSection) {
432 if (item.first == "unix") {
433 if (hasSeenUnix) {
434 BOOST_THROW_EXCEPTION(Error("Duplicate \"unix\" section"));
435 }
436 hasSeenUnix = true;
437
438 processSectionUnix(item.second, isDryRun);
439 }
440 else if (item.first == "tcp") {
441 if (hasSeenTcp) {
442 BOOST_THROW_EXCEPTION(Error("Duplicate \"tcp\" section"));
443 }
444 hasSeenTcp = true;
445
446 processSectionTcp(item.second, isDryRun);
447 }
448 else if (item.first == "udp") {
449 if (hasSeenUdp) {
450 BOOST_THROW_EXCEPTION(Error("Duplicate \"udp\" section"));
451 }
452 hasSeenUdp = true;
453
454 processSectionUdp(item.second, isDryRun, nicList);
455 }
456 else if (item.first == "ether") {
457 if (hasSeenEther) {
458 BOOST_THROW_EXCEPTION(Error("Duplicate \"ether\" section"));
459 }
460 hasSeenEther = true;
461
462 processSectionEther(item.second, isDryRun, nicList);
463 }
464 else if (item.first == "websocket") {
465 if (hasSeenWebSocket) {
466 BOOST_THROW_EXCEPTION(Error("Duplicate \"websocket\" section"));
467 }
468 hasSeenWebSocket = true;
469
470 processSectionWebSocket(item.second, isDryRun);
471 }
472 else {
473 BOOST_THROW_EXCEPTION(Error("Unrecognized option \"" + item.first + "\""));
474 }
475 }
476}
477
478void
479FaceManager::processSectionUnix(const ConfigSection& configSection, bool isDryRun)
480{
481 // ; the unix section contains settings of Unix stream faces and channels
482 // unix
483 // {
484 // path /var/run/nfd.sock ; Unix stream listener path
485 // }
486
487#if defined(HAVE_UNIX_SOCKETS)
Yanbiao Li73860e32015-08-19 16:30:16 -0700488 std::string path = "/var/run/nfd.sock";
489
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200490 for (const auto& i : configSection) {
491 if (i.first == "path") {
492 path = i.second.get_value<std::string>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700493 }
494 else {
495 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200496 i.first + "\" in \"unix\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700497 }
498 }
499
500 if (!isDryRun) {
501 if (m_factories.count("unix") > 0) {
502 return;
503 }
504
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200505 auto factory = make_shared<UnixStreamFactory>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700506 m_factories.insert(std::make_pair("unix", factory));
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200507
508 auto channel = factory->createChannel(path);
509 channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700510 }
511#else
512 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without Unix sockets support, "
513 "cannot process \"unix\" section"));
514#endif // HAVE_UNIX_SOCKETS
515}
516
517void
518FaceManager::processSectionTcp(const ConfigSection& configSection, bool isDryRun)
519{
520 // ; the tcp section contains settings of TCP faces and channels
521 // tcp
522 // {
523 // listen yes ; set to 'no' to disable TCP listener, default 'yes'
524 // port 6363 ; TCP listener port number
525 // }
526
Alexander Afanasyev9f5f1452016-09-08 15:22:46 -0700527#if defined(HAVE_TCP)
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200528 uint16_t port = 6363;
Yanbiao Li73860e32015-08-19 16:30:16 -0700529 bool needToListen = true;
530 bool enableV4 = true;
531 bool enableV6 = true;
532
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200533 for (const auto& i : configSection) {
534 if (i.first == "port") {
535 port = ConfigFile::parseNumber<uint16_t>(i, "tcp");
536 NFD_LOG_TRACE("TCP port set to " << port);
Yanbiao Li73860e32015-08-19 16:30:16 -0700537 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200538 else if (i.first == "listen") {
539 needToListen = ConfigFile::parseYesNo(i, "tcp");
Yanbiao Li73860e32015-08-19 16:30:16 -0700540 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200541 else if (i.first == "enable_v4") {
542 enableV4 = ConfigFile::parseYesNo(i, "tcp");
Yanbiao Li73860e32015-08-19 16:30:16 -0700543 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200544 else if (i.first == "enable_v6") {
545 enableV6 = ConfigFile::parseYesNo(i, "tcp");
Yanbiao Li73860e32015-08-19 16:30:16 -0700546 }
547 else {
548 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200549 i.first + "\" in \"tcp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700550 }
551 }
552
553 if (!enableV4 && !enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200554 BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 TCP channels have been disabled."
Yanbiao Li73860e32015-08-19 16:30:16 -0700555 " Remove \"tcp\" section to disable TCP channels or"
556 " re-enable at least one channel type."));
557 }
558
559 if (!isDryRun) {
560 if (m_factories.count("tcp") > 0) {
561 return;
562 }
563
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200564 auto factory = make_shared<TcpFactory>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700565 m_factories.insert(std::make_pair("tcp", factory));
566
567 if (enableV4) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200568 tcp::Endpoint endpoint(boost::asio::ip::tcp::v4(), port);
569 shared_ptr<TcpChannel> v4Channel = factory->createChannel(endpoint);
Yanbiao Li73860e32015-08-19 16:30:16 -0700570 if (needToListen) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200571 v4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700572 }
573
574 m_factories.insert(std::make_pair("tcp4", factory));
575 }
576
577 if (enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200578 tcp::Endpoint endpoint(boost::asio::ip::tcp::v6(), port);
579 shared_ptr<TcpChannel> v6Channel = factory->createChannel(endpoint);
Yanbiao Li73860e32015-08-19 16:30:16 -0700580 if (needToListen) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200581 v6Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700582 }
583
584 m_factories.insert(std::make_pair("tcp6", factory));
585 }
586 }
Alexander Afanasyev9f5f1452016-09-08 15:22:46 -0700587#else
588 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without TCP support, cannot process \"tcp\" section"));
589#endif // HAVE_TCP
Yanbiao Li73860e32015-08-19 16:30:16 -0700590}
591
592void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200593FaceManager::processSectionUdp(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700594 const std::vector<NetworkInterfaceInfo>& nicList)
595{
596 // ; the udp section contains settings of UDP faces and channels
597 // udp
598 // {
599 // port 6363 ; UDP unicast port number
600 // idle_timeout 600 ; idle time (seconds) before closing a UDP unicast face
601 // keep_alive_interval 25 ; interval (seconds) between keep-alive refreshes
602
603 // ; NFD creates one UDP multicast face per NIC
604 // mcast yes ; set to 'no' to disable UDP multicast, default 'yes'
605 // mcast_port 56363 ; UDP multicast port number
606 // mcast_group 224.0.23.170 ; UDP multicast group (IPv4 only)
607 // }
608
Alexander Afanasyev9f5f1452016-09-08 15:22:46 -0700609#if defined(HAVE_UDP)
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200610 uint16_t port = 6363;
Yanbiao Li73860e32015-08-19 16:30:16 -0700611 bool enableV4 = true;
612 bool enableV6 = true;
613 size_t timeout = 600;
614 size_t keepAliveInterval = 25;
615 bool useMcast = true;
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200616 auto mcastGroup = boost::asio::ip::address_v4::from_string("224.0.23.170");
617 uint16_t mcastPort = 56363;
Yanbiao Li73860e32015-08-19 16:30:16 -0700618
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200619 for (const auto& i : configSection) {
620 if (i.first == "port") {
621 port = ConfigFile::parseNumber<uint16_t>(i, "udp");
622 NFD_LOG_TRACE("UDP unicast port set to " << port);
623 }
624 else if (i.first == "enable_v4") {
625 enableV4 = ConfigFile::parseYesNo(i, "udp");
626 }
627 else if (i.first == "enable_v6") {
628 enableV6 = ConfigFile::parseYesNo(i, "udp");
629 }
630 else if (i.first == "idle_timeout") {
Yanbiao Li73860e32015-08-19 16:30:16 -0700631 try {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200632 timeout = i.second.get_value<size_t>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700633 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200634 catch (const boost::property_tree::ptree_bad_data&) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700635 BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200636 i.first + "\" in \"udp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700637 }
638 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200639 else if (i.first == "keep_alive_interval") {
Yanbiao Li73860e32015-08-19 16:30:16 -0700640 try {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200641 keepAliveInterval = i.second.get_value<size_t>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700642 /// \todo Make use of keepAliveInterval
Yanbiao Li73860e32015-08-19 16:30:16 -0700643 (void)(keepAliveInterval);
644 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200645 catch (const boost::property_tree::ptree_bad_data&) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700646 BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200647 i.first + "\" in \"udp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700648 }
649 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200650 else if (i.first == "mcast") {
651 useMcast = ConfigFile::parseYesNo(i, "udp");
Yanbiao Li73860e32015-08-19 16:30:16 -0700652 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200653 else if (i.first == "mcast_port") {
654 mcastPort = ConfigFile::parseNumber<uint16_t>(i, "udp");
655 NFD_LOG_TRACE("UDP multicast port set to " << mcastPort);
Yanbiao Li73860e32015-08-19 16:30:16 -0700656 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200657 else if (i.first == "mcast_group") {
658 boost::system::error_code ec;
659 mcastGroup = boost::asio::ip::address_v4::from_string(i.second.get_value<std::string>(), ec);
660 if (ec) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700661 BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200662 i.first + "\" in \"udp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700663 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200664 NFD_LOG_TRACE("UDP multicast group set to " << mcastGroup);
Yanbiao Li73860e32015-08-19 16:30:16 -0700665 }
666 else {
667 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200668 i.first + "\" in \"udp\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700669 }
670 }
671
672 if (!enableV4 && !enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200673 BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 UDP channels have been disabled."
Yanbiao Li73860e32015-08-19 16:30:16 -0700674 " Remove \"udp\" section to disable UDP channels or"
675 " re-enable at least one channel type."));
676 }
677 else if (useMcast && !enableV4) {
678 BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 multicast requested, but IPv4 channels"
679 " have been disabled (conflicting configuration options set)"));
680 }
681
682 if (!isDryRun) {
683 shared_ptr<UdpFactory> factory;
684 bool isReload = false;
685 if (m_factories.count("udp") > 0) {
686 isReload = true;
687 factory = static_pointer_cast<UdpFactory>(m_factories["udp"]);
688 }
689 else {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200690 factory = make_shared<UdpFactory>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700691 m_factories.insert(std::make_pair("udp", factory));
692 }
693
694 if (!isReload && enableV4) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200695 udp::Endpoint endpoint(boost::asio::ip::udp::v4(), port);
696 shared_ptr<UdpChannel> v4Channel = factory->createChannel(endpoint, time::seconds(timeout));
697 v4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700698
699 m_factories.insert(std::make_pair("udp4", factory));
700 }
701
702 if (!isReload && enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200703 udp::Endpoint endpoint(boost::asio::ip::udp::v6(), port);
704 shared_ptr<UdpChannel> v6Channel = factory->createChannel(endpoint, time::seconds(timeout));
705 v6Channel->listen(bind(&FaceTable::add, &m_faceTable, _1), nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700706
Yanbiao Li73860e32015-08-19 16:30:16 -0700707 m_factories.insert(std::make_pair("udp6", factory));
708 }
709
Junxiao Shicde37ad2015-12-24 01:02:05 -0700710 std::set<shared_ptr<Face>> multicastFacesToRemove;
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200711 for (const auto& i : factory->getMulticastFaces()) {
712 multicastFacesToRemove.insert(i.second);
713 }
714
Yanbiao Li73860e32015-08-19 16:30:16 -0700715 if (useMcast && enableV4) {
716 std::vector<NetworkInterfaceInfo> ipv4MulticastInterfaces;
717 for (const auto& nic : nicList) {
718 if (nic.isUp() && nic.isMulticastCapable() && !nic.ipv4Addresses.empty()) {
719 ipv4MulticastInterfaces.push_back(nic);
720 }
721 }
722
723 bool isNicNameNecessary = false;
724#if defined(__linux__)
725 if (ipv4MulticastInterfaces.size() > 1) {
726 // On Linux if we have more than one MulticastUdpFace
727 // we need to specify the name of the interface
728 isNicNameNecessary = true;
729 }
730#endif
731
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200732 udp::Endpoint mcastEndpoint(mcastGroup, mcastPort);
Yanbiao Li73860e32015-08-19 16:30:16 -0700733 for (const auto& nic : ipv4MulticastInterfaces) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200734 udp::Endpoint localEndpoint(nic.ipv4Addresses[0], mcastPort);
735 auto newFace = factory->createMulticastFace(localEndpoint, mcastEndpoint,
Yukai Tu0a49d342015-09-13 12:54:22 +0800736 isNicNameNecessary ? nic.name : "");
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200737 m_faceTable.add(newFace);
738 multicastFacesToRemove.erase(newFace);
Yanbiao Li73860e32015-08-19 16:30:16 -0700739 }
740 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700741
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200742 for (const auto& face : multicastFacesToRemove) {
743 face->close();
Yanbiao Li73860e32015-08-19 16:30:16 -0700744 }
745 }
Alexander Afanasyev9f5f1452016-09-08 15:22:46 -0700746#else
747 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without UDP support, cannot process \"udp\" section"));
748#endif // HAVE_UDP
Yanbiao Li73860e32015-08-19 16:30:16 -0700749}
750
751void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200752FaceManager::processSectionEther(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700753 const std::vector<NetworkInterfaceInfo>& nicList)
754{
755 // ; the ether section contains settings of Ethernet faces and channels
756 // ether
757 // {
758 // ; NFD creates one Ethernet multicast face per NIC
759 // mcast yes ; set to 'no' to disable Ethernet multicast, default 'yes'
760 // mcast_group 01:00:5E:00:17:AA ; Ethernet multicast group
761 // }
762
763#if defined(HAVE_LIBPCAP)
764 bool useMcast = true;
765 ethernet::Address mcastGroup(ethernet::getDefaultMulticastAddress());
766
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200767 for (const auto& i : configSection) {
768 if (i.first == "mcast") {
769 useMcast = ConfigFile::parseYesNo(i, "ether");
Yanbiao Li73860e32015-08-19 16:30:16 -0700770 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200771 else if (i.first == "mcast_group") {
772 mcastGroup = ethernet::Address::fromString(i.second.get_value<std::string>());
Yanbiao Li73860e32015-08-19 16:30:16 -0700773 if (mcastGroup.isNull()) {
774 BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200775 i.first + "\" in \"ether\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700776 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200777 NFD_LOG_TRACE("Ethernet multicast group set to " << mcastGroup);
Yanbiao Li73860e32015-08-19 16:30:16 -0700778 }
779 else {
780 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200781 i.first + "\" in \"ether\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700782 }
783 }
784
785 if (!isDryRun) {
786 shared_ptr<EthernetFactory> factory;
787 if (m_factories.count("ether") > 0) {
788 factory = static_pointer_cast<EthernetFactory>(m_factories["ether"]);
789 }
790 else {
791 factory = make_shared<EthernetFactory>();
792 m_factories.insert(std::make_pair("ether", factory));
793 }
794
Junxiao Shicde37ad2015-12-24 01:02:05 -0700795 std::set<shared_ptr<Face>> multicastFacesToRemove;
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200796 for (const auto& i : factory->getMulticastFaces()) {
797 multicastFacesToRemove.insert(i.second);
798 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700799
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200800 if (useMcast) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700801 for (const auto& nic : nicList) {
802 if (nic.isUp() && nic.isMulticastCapable()) {
803 try {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200804 auto newFace = factory->createMulticastFace(nic, mcastGroup);
805 m_faceTable.add(newFace);
806 multicastFacesToRemove.erase(newFace);
Yanbiao Li73860e32015-08-19 16:30:16 -0700807 }
808 catch (const EthernetFactory::Error& factoryError) {
809 NFD_LOG_ERROR(factoryError.what() << ", continuing");
810 }
Davide Pesavento35120ea2015-11-17 21:13:18 +0100811 catch (const face::EthernetTransport::Error& faceError) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700812 NFD_LOG_ERROR(faceError.what() << ", continuing");
813 }
814 }
815 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700816 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700817
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200818 for (const auto& face : multicastFacesToRemove) {
819 face->close();
Yanbiao Li73860e32015-08-19 16:30:16 -0700820 }
821 }
822#else
823 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without libpcap, cannot process \"ether\" section"));
824#endif // HAVE_LIBPCAP
825}
826
827void
828FaceManager::processSectionWebSocket(const ConfigSection& configSection, bool isDryRun)
829{
830 // ; the websocket section contains settings of WebSocket faces and channels
831 // websocket
832 // {
833 // listen yes ; set to 'no' to disable WebSocket listener, default 'yes'
834 // port 9696 ; WebSocket listener port number
835 // enable_v4 yes ; set to 'no' to disable listening on IPv4 socket, default 'yes'
836 // enable_v6 yes ; set to 'no' to disable listening on IPv6 socket, default 'yes'
837 // }
838
839#if defined(HAVE_WEBSOCKET)
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200840 uint16_t port = 9696;
Yanbiao Li73860e32015-08-19 16:30:16 -0700841 bool needToListen = true;
842 bool enableV4 = true;
843 bool enableV6 = true;
844
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200845 for (const auto& i : configSection) {
846 if (i.first == "port") {
847 port = ConfigFile::parseNumber<uint16_t>(i, "websocket");
848 NFD_LOG_TRACE("WebSocket port set to " << port);
Yanbiao Li73860e32015-08-19 16:30:16 -0700849 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200850 else if (i.first == "listen") {
851 needToListen = ConfigFile::parseYesNo(i, "websocket");
Yanbiao Li73860e32015-08-19 16:30:16 -0700852 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200853 else if (i.first == "enable_v4") {
854 enableV4 = ConfigFile::parseYesNo(i, "websocket");
Yanbiao Li73860e32015-08-19 16:30:16 -0700855 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200856 else if (i.first == "enable_v6") {
857 enableV6 = ConfigFile::parseYesNo(i, "websocket");
Yanbiao Li73860e32015-08-19 16:30:16 -0700858 }
859 else {
860 BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200861 i.first + "\" in \"websocket\" section"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700862 }
863 }
864
865 if (!enableV4 && !enableV6) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200866 BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 WebSocket channels have been disabled."
Yanbiao Li73860e32015-08-19 16:30:16 -0700867 " Remove \"websocket\" section to disable WebSocket channels or"
868 " re-enable at least one channel type."));
869 }
870
871 if (!enableV4 && enableV6) {
872 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD does not allow pure IPv6 WebSocket channel."));
873 }
874
875 if (!isDryRun) {
876 if (m_factories.count("websocket") > 0) {
877 return;
878 }
879
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200880 auto factory = make_shared<WebSocketFactory>();
Yanbiao Li73860e32015-08-19 16:30:16 -0700881 m_factories.insert(std::make_pair("websocket", factory));
882
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200883 shared_ptr<WebSocketChannel> channel;
884
Yanbiao Li73860e32015-08-19 16:30:16 -0700885 if (enableV6 && enableV4) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200886 websocket::Endpoint endpoint(boost::asio::ip::address_v6::any(), port);
887 channel = factory->createChannel(endpoint);
Yanbiao Li73860e32015-08-19 16:30:16 -0700888
889 m_factories.insert(std::make_pair("websocket46", factory));
890 }
891 else if (enableV4) {
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200892 websocket::Endpoint endpoint(boost::asio::ip::address_v4::any(), port);
893 channel = factory->createChannel(endpoint);
Yanbiao Li73860e32015-08-19 16:30:16 -0700894
895 m_factories.insert(std::make_pair("websocket4", factory));
896 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200897
898 if (channel && needToListen) {
899 channel->listen(bind(&FaceTable::add, &m_faceTable, _1));
900 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700901 }
902#else
903 BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without WebSocket, "
904 "cannot process \"websocket\" section"));
905#endif // HAVE_WEBSOCKET
906}
907
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200908} // namespace nfd