blob: 0aa5a1e0e80cd84b503935cefda10d9b5e9888c3 [file] [log] [blame]
Vince Lehman27f1add2014-10-16 17:14:46 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 **/
21
22#include "face-controller.hpp"
Vince Lehman0a7da612014-10-29 14:39:29 -050023
24#include "common.hpp"
Vince Lehman27f1add2014-10-16 17:14:46 -050025#include "logger.hpp"
26
27namespace nlsr {
28namespace util {
29
30INIT_LOGGER("FaceController");
31
32using ndn::util::FaceUri;
33
34const ndn::time::seconds FaceController::TIME_ALLOWED_FOR_CANONIZATION = ndn::time::seconds(4);
35
36void
37FaceController::createFace(const std::string& request,
38 const CommandSuccessCallback& onSuccess,
39 const CommandFailureCallback& onFailure)
40{
41 FaceUri uri(request);
42
43 _LOG_TRACE("Converting " << uri << " to canonical form");
44 uri.canonize(bind(&FaceController::onCanonizeSuccess, this, _1, onSuccess, onFailure, uri),
45 bind(&FaceController::onCanonizeFailure, this, _1, onSuccess, onFailure, uri),
46 m_ioService, TIME_ALLOWED_FOR_CANONIZATION);
47}
48
49void
50FaceController::createFaceInNfd(const FaceUri& uri,
51 const CommandSuccessCallback& onSuccess,
52 const CommandFailureCallback& onFailure)
53{
54 ndn::nfd::ControlParameters faceParameters;
55 faceParameters.setUri(uri.toString());
56
57 _LOG_DEBUG("Creating Face in NFD with face-uri: " << uri);
58 m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters, onSuccess, onFailure);
59}
60
61void
62FaceController::onCanonizeSuccess(const FaceUri& uri,
63 const CommandSuccessCallback& onSuccess,
64 const CommandFailureCallback& onFailure,
65 const FaceUri& request)
66{
67 _LOG_DEBUG("Converted " << request << " to canonical form: " << uri);
68
69 createFaceInNfd(uri, onSuccess, onFailure);
70}
71
72void
73FaceController::onCanonizeFailure(const std::string& reason,
74 const CommandSuccessCallback& onSuccess,
75 const CommandFailureCallback& onFailure,
76 const FaceUri& request)
77{
78 _LOG_WARN("Could not convert " << request << " to canonical form: " << reason);
79 onFailure(CANONIZE_ERROR_CODE, "Could not canonize face-uri: " + request.toString());
80}
81
82} // namespace util
83} // namespace nlsr