blob: 4cc3288e7acbdb93f699d17dcbe8e83b233c41c0 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi38b24c72017-01-05 02:59:31 +00003 * Copyright (c) 2014-2017, 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"
Junxiao Shi40cb61c2015-09-23 18:36:45 -070027#include "face/generic-link-service.hpp"
Junxiao Shib8590312016-12-29 21:22:25 +000028#include "face/protocol-factory.hpp"
Yukai Tu0a49d342015-09-13 12:54:22 +080029#include "fw/face-table.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070030
Junxiao Shicbc8e942016-09-06 03:17:45 +000031#include <ndn-cxx/lp/tags.hpp>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000032#include <ndn-cxx/mgmt/nfd/channel-status.hpp>
Yanbiao Li73860e32015-08-19 16:30:16 -070033
Yanbiao Li73860e32015-08-19 16:30:16 -070034namespace nfd {
35
36NFD_LOG_INIT("FaceManager");
37
Junxiao Shiea47bde2017-01-26 17:49:16 +000038FaceManager::FaceManager(FaceSystem& faceSystem,
39 Dispatcher& dispatcher, CommandAuthenticator& authenticator)
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000040 : NfdManagerBase(dispatcher, authenticator, "faces")
Junxiao Shiea47bde2017-01-26 17:49:16 +000041 , m_faceSystem(faceSystem)
42 , m_faceTable(faceSystem.getFaceTable())
Yanbiao Li73860e32015-08-19 16:30:16 -070043{
Yanbiao Li58ba3f92017-02-15 14:27:18 +000044 // register handlers for ControlCommand
Yanbiao Li73860e32015-08-19 16:30:16 -070045 registerCommandHandler<ndn::nfd::FaceCreateCommand>("create",
46 bind(&FaceManager::createFace, this, _2, _3, _4, _5));
47
Eric Newberryb5aa7f52016-09-03 20:36:12 -070048 registerCommandHandler<ndn::nfd::FaceUpdateCommand>("update",
49 bind(&FaceManager::updateFace, this, _2, _3, _4, _5));
50
Yanbiao Li73860e32015-08-19 16:30:16 -070051 registerCommandHandler<ndn::nfd::FaceDestroyCommand>("destroy",
52 bind(&FaceManager::destroyFace, this, _2, _3, _4, _5));
53
Yanbiao Li58ba3f92017-02-15 14:27:18 +000054 // register handlers for StatusDataset
Yanbiao Li73860e32015-08-19 16:30:16 -070055 registerStatusDatasetHandler("list", bind(&FaceManager::listFaces, this, _1, _2, _3));
56 registerStatusDatasetHandler("channels", bind(&FaceManager::listChannels, this, _1, _2, _3));
57 registerStatusDatasetHandler("query", bind(&FaceManager::queryFaces, this, _1, _2, _3));
58
Yanbiao Li58ba3f92017-02-15 14:27:18 +000059 // register notification stream
Junxiao Shiae04d342016-07-19 13:20:22 +000060 m_postNotification = registerNotificationStream("events");
Eric Newberry1b4ba052016-10-07 23:04:07 -070061 m_faceAddConn = m_faceTable.afterAdd.connect([this] (const Face& face) {
62 connectFaceStateChangeSignal(face);
63 notifyFaceEvent(face, ndn::nfd::FACE_EVENT_CREATED);
64 });
65 m_faceRemoveConn = m_faceTable.beforeRemove.connect([this] (const Face& face) {
66 notifyFaceEvent(face, ndn::nfd::FACE_EVENT_DESTROYED);
67 });
Yanbiao Li73860e32015-08-19 16:30:16 -070068}
69
70void
71FaceManager::setConfigFile(ConfigFile& configFile)
72{
Junxiao Shib8590312016-12-29 21:22:25 +000073 m_faceSystem.setConfigFile(configFile);
Yanbiao Li73860e32015-08-19 16:30:16 -070074}
75
76void
77FaceManager::createFace(const Name& topPrefix, const Interest& interest,
78 const ControlParameters& parameters,
79 const ndn::mgmt::CommandContinuation& done)
80{
Eric Newberry78e32b02017-04-01 14:34:44 +000081 FaceUri remoteUri;
82 if (!remoteUri.parse(parameters.getUri())) {
83 NFD_LOG_TRACE("failed to parse remote URI: " << parameters.getUri());
Eric Newberry42602412016-08-27 09:33:18 -070084 done(ControlResponse(400, "Malformed command"));
85 return;
Yanbiao Li73860e32015-08-19 16:30:16 -070086 }
87
Eric Newberry78e32b02017-04-01 14:34:44 +000088 if (!remoteUri.isCanonical()) {
89 NFD_LOG_TRACE("received non-canonical remote URI: " << remoteUri.toString());
90 done(ControlResponse(400, "Non-canonical remote URI"));
Eric Newberry42602412016-08-27 09:33:18 -070091 return;
Yanbiao Li73860e32015-08-19 16:30:16 -070092 }
93
Eric Newberry78e32b02017-04-01 14:34:44 +000094 ndn::optional<FaceUri> localUri;
95 if (parameters.hasLocalUri()) {
96 localUri = FaceUri{};
97
98 if (!localUri->parse(parameters.getLocalUri())) {
99 NFD_LOG_TRACE("failed to parse local URI: " << parameters.getLocalUri());
100 done(ControlResponse(400, "Malformed command"));
101 return;
102 }
103
104 if (!localUri->isCanonical()) {
105 NFD_LOG_TRACE("received non-canonical local URI: " << localUri->toString());
106 done(ControlResponse(400, "Non-canonical local URI"));
107 return;
108 }
109 }
110
111 ProtocolFactory* factory = m_faceSystem.getFactoryByScheme(remoteUri.getScheme());
Junxiao Shib8590312016-12-29 21:22:25 +0000112 if (factory == nullptr) {
Eric Newberry78e32b02017-04-01 14:34:44 +0000113 NFD_LOG_TRACE("received create request for unsupported protocol: " << remoteUri.getScheme());
Eric Newberry42602412016-08-27 09:33:18 -0700114 done(ControlResponse(406, "Unsupported protocol"));
115 return;
Yanbiao Li73860e32015-08-19 16:30:16 -0700116 }
117
118 try {
Eric Newberry78e32b02017-04-01 14:34:44 +0000119 factory->createFace(remoteUri,
120 localUri,
Junxiao Shib8590312016-12-29 21:22:25 +0000121 parameters.getFacePersistency(),
122 parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
123 parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED),
124 bind(&FaceManager::afterCreateFaceSuccess, this, parameters, _1, done),
125 bind(&FaceManager::afterCreateFaceFailure, this, _1, _2, done));
Yanbiao Li73860e32015-08-19 16:30:16 -0700126 }
127 catch (const std::runtime_error& error) {
Eric Newberry42602412016-08-27 09:33:18 -0700128 NFD_LOG_ERROR("Face creation failed: " << error.what());
129 done(ControlResponse(500, "Face creation failed due to internal error"));
130 return;
Yanbiao Li73860e32015-08-19 16:30:16 -0700131 }
132 catch (const std::logic_error& error) {
Eric Newberry42602412016-08-27 09:33:18 -0700133 NFD_LOG_ERROR("Face creation failed: " << error.what());
134 done(ControlResponse(500, "Face creation failed due to internal error"));
135 return;
Yanbiao Li73860e32015-08-19 16:30:16 -0700136 }
137}
138
139void
Eric Newberry42602412016-08-27 09:33:18 -0700140FaceManager::afterCreateFaceSuccess(const ControlParameters& parameters,
Eric Newberryf40551a2016-09-05 15:41:16 -0700141 const shared_ptr<Face>& face,
Yanbiao Li73860e32015-08-19 16:30:16 -0700142 const ndn::mgmt::CommandContinuation& done)
143{
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000144 if (face->getId() != face::INVALID_FACEID) {// Face already exists
145 NFD_LOG_TRACE("Attempted to create duplicate face of " << face->getId());
146
147 ControlParameters response = collectFaceProperties(*face);
148 response.setUri(face->getRemoteUri().toString());
149 done(ControlResponse(409, "Face with remote URI already exists").setBody(response.wireEncode()));
150 return;
151 }
152
Eric Newberryf40551a2016-09-05 15:41:16 -0700153 // If scope non-local and flags set to enable local fields, request shouldn't
154 // have made it this far
155 BOOST_ASSERT(face->getScope() == ndn::nfd::FACE_SCOPE_LOCAL ||
156 !parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) ||
157 (parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
158 !parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)));
159
160 m_faceTable.add(face);
161
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000162 ControlParameters response = collectFaceProperties(*face);
Eric Newberry42602412016-08-27 09:33:18 -0700163 done(ControlResponse(200, "OK").setBody(response.wireEncode()));
164}
165
166void
167FaceManager::afterCreateFaceFailure(uint32_t status,
168 const std::string& reason,
169 const ndn::mgmt::CommandContinuation& done)
170{
171 NFD_LOG_DEBUG("Face creation failed: " << reason);
172
173 done(ControlResponse(status, reason));
Yanbiao Li73860e32015-08-19 16:30:16 -0700174}
175
176void
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700177FaceManager::updateFace(const Name& topPrefix, const Interest& interest,
178 const ControlParameters& parameters,
179 const ndn::mgmt::CommandContinuation& done)
180{
181 FaceId faceId = parameters.getFaceId();
182 if (faceId == 0) {
183 // Self-updating
184 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = interest.getTag<lp::IncomingFaceIdTag>();
185 if (incomingFaceIdTag == nullptr) {
186 NFD_LOG_TRACE("unable to determine face for self-update");
187 done(ControlResponse(404, "No FaceId specified and IncomingFaceId not available"));
188 return;
189 }
190 faceId = *incomingFaceIdTag;
191 }
192
193 Face* face = m_faceTable.get(faceId);
194
195 if (face == nullptr) {
196 NFD_LOG_TRACE("invalid face specified");
197 done(ControlResponse(404, "Specified face does not exist"));
198 return;
199 }
200
201 // Verify validity of requested changes
202 ControlParameters response;
203 bool areParamsValid = true;
204
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700205 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
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000214 // check whether the requested FacePersistency change is valid if it's present
215 if (parameters.hasFacePersistency()) {
216 auto persistency = parameters.getFacePersistency();
217 if (!face->getTransport()->canChangePersistencyTo(persistency)) {
218 NFD_LOG_TRACE("cannot change face persistency to " << persistency);
219 areParamsValid = false;
220 response.setFacePersistency(persistency);
221 }
222 }
223
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700224 if (!areParamsValid) {
225 done(ControlResponse(409, "Invalid properties specified").setBody(response.wireEncode()));
226 return;
227 }
228
229 // All specified properties are valid, so make changes
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000230 if (parameters.hasFacePersistency()) {
231 face->setPersistency(parameters.getFacePersistency());
232 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700233 setLinkServiceOptions(*face, parameters, response);
234
Eric Newberryf40551a2016-09-05 15:41:16 -0700235 // Set ControlResponse fields
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000236 response = collectFaceProperties(*face);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700237
238 done(ControlResponse(200, "OK").setBody(response.wireEncode()));
239}
240
241void
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700242FaceManager::destroyFace(const Name& topPrefix, const Interest& interest,
243 const ControlParameters& parameters,
244 const ndn::mgmt::CommandContinuation& done)
245{
Junxiao Shi5b43f9a2016-07-19 13:15:56 +0000246 Face* face = m_faceTable.get(parameters.getFaceId());
247 if (face != nullptr) {
248 face->close();
Junxiao Shi40cb61c2015-09-23 18:36:45 -0700249 }
250
251 done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
252}
253
254void
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700255FaceManager::setLinkServiceOptions(Face& face,
256 const ControlParameters& parameters,
257 ControlParameters& response)
258{
259 auto linkService = dynamic_cast<face::GenericLinkService*>(face.getLinkService());
260 BOOST_ASSERT(linkService != nullptr);
261
262 auto options = linkService->getOptions();
263 if (parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
264 face.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) {
265 options.allowLocalFields = parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
266 }
267 linkService->setOptions(options);
268
269 // Set Flags for ControlResponse
270 response.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, options.allowLocalFields, false);
271}
272
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000273ControlParameters
274FaceManager::collectFaceProperties(const Face& face)
275{
276 auto linkService = dynamic_cast<face::GenericLinkService*>(face.getLinkService());
277 BOOST_ASSERT(linkService != nullptr);
278 auto options = linkService->getOptions();
279
280 return ControlParameters()
281 .setFaceId(face.getId())
282 .setFacePersistency(face.getPersistency())
283 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, options.allowLocalFields, false);
284}
285
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700286void
Yanbiao Li73860e32015-08-19 16:30:16 -0700287FaceManager::listFaces(const Name& topPrefix, const Interest& interest,
288 ndn::mgmt::StatusDatasetContext& context)
289{
Eric Newberryc64d30a2015-12-26 11:07:27 -0700290 auto now = time::steady_clock::now();
Junxiao Shib84e6742016-07-19 13:16:22 +0000291 for (const Face& face : m_faceTable) {
292 ndn::nfd::FaceStatus status = collectFaceStatus(face, now);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700293 context.append(status.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700294 }
295 context.end();
296}
297
298void
299FaceManager::listChannels(const Name& topPrefix, const Interest& interest,
300 ndn::mgmt::StatusDatasetContext& context)
301{
Junxiao Shib8590312016-12-29 21:22:25 +0000302 std::set<const ProtocolFactory*> factories = m_faceSystem.listProtocolFactories();
303 for (const ProtocolFactory* factory : factories) {
304 for (const auto& channel : factory->getChannels()) {
305 ndn::nfd::ChannelStatus entry;
306 entry.setLocalUri(channel->getUri().toString());
307 context.append(entry.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700308 }
309 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700310 context.end();
311}
312
313void
314FaceManager::queryFaces(const Name& topPrefix, const Interest& interest,
315 ndn::mgmt::StatusDatasetContext& context)
316{
317 ndn::nfd::FaceQueryFilter faceFilter;
318 const Name& query = interest.getName();
319 try {
320 faceFilter.wireDecode(query[-1].blockFromValue());
321 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200322 catch (const tlv::Error& e) {
323 NFD_LOG_DEBUG("Malformed query filter: " << e.what());
324 return context.reject(ControlResponse(400, "Malformed filter"));
Yanbiao Li73860e32015-08-19 16:30:16 -0700325 }
326
Eric Newberryc64d30a2015-12-26 11:07:27 -0700327 auto now = time::steady_clock::now();
Junxiao Shib84e6742016-07-19 13:16:22 +0000328 for (const Face& face : m_faceTable) {
329 if (!matchFilter(faceFilter, face)) {
Junxiao Shida93f1f2015-11-11 06:13:16 -0700330 continue;
Yanbiao Li73860e32015-08-19 16:30:16 -0700331 }
Junxiao Shib84e6742016-07-19 13:16:22 +0000332 ndn::nfd::FaceStatus status = collectFaceStatus(face, now);
Junxiao Shida93f1f2015-11-11 06:13:16 -0700333 context.append(status.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700334 }
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200335
Yanbiao Li73860e32015-08-19 16:30:16 -0700336 context.end();
337}
338
339bool
Junxiao Shib84e6742016-07-19 13:16:22 +0000340FaceManager::matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face)
Yanbiao Li73860e32015-08-19 16:30:16 -0700341{
342 if (filter.hasFaceId() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000343 filter.getFaceId() != static_cast<uint64_t>(face.getId())) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700344 return false;
345 }
346
347 if (filter.hasUriScheme() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000348 filter.getUriScheme() != face.getRemoteUri().getScheme() &&
349 filter.getUriScheme() != face.getLocalUri().getScheme()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700350 return false;
351 }
352
353 if (filter.hasRemoteUri() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000354 filter.getRemoteUri() != face.getRemoteUri().toString()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700355 return false;
356 }
357
358 if (filter.hasLocalUri() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000359 filter.getLocalUri() != face.getLocalUri().toString()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700360 return false;
361 }
362
363 if (filter.hasFaceScope() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000364 filter.getFaceScope() != face.getScope()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700365 return false;
366 }
367
368 if (filter.hasFacePersistency() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000369 filter.getFacePersistency() != face.getPersistency()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700370 return false;
371 }
372
373 if (filter.hasLinkType() &&
Junxiao Shib84e6742016-07-19 13:16:22 +0000374 filter.getLinkType() != face.getLinkType()) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700375 return false;
376 }
377
378 return true;
379}
380
Eric Newberryc64d30a2015-12-26 11:07:27 -0700381ndn::nfd::FaceStatus
382FaceManager::collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now)
383{
384 ndn::nfd::FaceStatus status;
385
386 collectFaceProperties(face, status);
387
388 time::steady_clock::TimePoint expirationTime = face.getExpirationTime();
389 if (expirationTime != time::steady_clock::TimePoint::max()) {
390 status.setExpirationPeriod(std::max(time::milliseconds(0),
391 time::duration_cast<time::milliseconds>(expirationTime - now)));
392 }
393
394 const face::FaceCounters& counters = face.getCounters();
395 status.setNInInterests(counters.nInInterests)
396 .setNOutInterests(counters.nOutInterests)
Junxiao Shif03d4792017-04-06 16:41:22 +0000397 .setNInData(counters.nInData)
398 .setNOutData(counters.nOutData)
Eric Newberryc64d30a2015-12-26 11:07:27 -0700399 .setNInNacks(counters.nInNacks)
400 .setNOutNacks(counters.nOutNacks)
401 .setNInBytes(counters.nInBytes)
402 .setNOutBytes(counters.nOutBytes);
403
404 return status;
405}
406
Junxiao Shida93f1f2015-11-11 06:13:16 -0700407template<typename FaceTraits>
Junxiao Shicde37ad2015-12-24 01:02:05 -0700408void
409FaceManager::collectFaceProperties(const Face& face, FaceTraits& traits)
Junxiao Shida93f1f2015-11-11 06:13:16 -0700410{
411 traits.setFaceId(face.getId())
412 .setRemoteUri(face.getRemoteUri().toString())
413 .setLocalUri(face.getLocalUri().toString())
414 .setFaceScope(face.getScope())
415 .setFacePersistency(face.getPersistency())
416 .setLinkType(face.getLinkType());
Eric Newberry1b4ba052016-10-07 23:04:07 -0700417
418 // Set Flag bits
419 auto linkService = dynamic_cast<face::GenericLinkService*>(face.getLinkService());
420 if (linkService != nullptr) {
421 auto linkServiceOptions = linkService->getOptions();
422 traits.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, linkServiceOptions.allowLocalFields);
423 }
Junxiao Shida93f1f2015-11-11 06:13:16 -0700424}
425
426void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700427FaceManager::notifyFaceEvent(const Face& face, ndn::nfd::FaceEventKind kind)
Yanbiao Li73860e32015-08-19 16:30:16 -0700428{
429 ndn::nfd::FaceEventNotification notification;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700430 notification.setKind(kind);
Junxiao Shiae04d342016-07-19 13:20:22 +0000431 collectFaceProperties(face, notification);
Yanbiao Li73860e32015-08-19 16:30:16 -0700432
Junxiao Shiae04d342016-07-19 13:20:22 +0000433 m_postNotification(notification.wireEncode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700434}
435
436void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700437FaceManager::connectFaceStateChangeSignal(const Face& face)
Yanbiao Li73860e32015-08-19 16:30:16 -0700438{
Eric Newberry1b4ba052016-10-07 23:04:07 -0700439 FaceId faceId = face.getId();
440 m_faceStateChangeConn[faceId] = face.afterStateChange.connect(
441 [this, faceId] (face::FaceState oldState, face::FaceState newState) {
442 const Face& face = *m_faceTable.get(faceId);
Yanbiao Li73860e32015-08-19 16:30:16 -0700443
Eric Newberry1b4ba052016-10-07 23:04:07 -0700444 if (newState == face::FaceState::UP) {
445 notifyFaceEvent(face, ndn::nfd::FACE_EVENT_UP);
446 }
447 else if (newState == face::FaceState::DOWN) {
448 notifyFaceEvent(face, ndn::nfd::FACE_EVENT_DOWN);
449 }
450 else if (newState == face::FaceState::CLOSED) {
451 m_faceStateChangeConn.erase(faceId);
452 }
453 });
Yanbiao Li73860e32015-08-19 16:30:16 -0700454}
455
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200456} // namespace nfd