32 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
36 using nfd::ControlParameters;
37 using nfd::ControlResponse;
46 , m_keyChain(keyChain)
47 , m_controller(face, keyChain)
54 BOOST_ASSERT(m_stages.empty());
56 BOOST_ASSERT(!m_stages.empty());
58 for (
size_t i = 0; i < m_stages.size(); ++i) {
59 m_stages[i]->onSuccess.connect([
this] (
const auto& uri) { connect(uri); });
60 if (i + 1 < m_stages.size()) {
61 m_stages[i]->onFailure.connect([=] (
const auto&) { m_stages[i + 1]->start(); });
64 m_stages[i]->onFailure.connect([=] (
const auto&) {
onComplete(
false); });
70 Procedure::makeStages(
const Options& options)
72 m_stages.push_back(make_unique<MulticastDiscovery>(m_face, m_controller));
73 m_stages.push_back(make_unique<GuessFromSearchDomains>());
74 m_stages.push_back(make_unique<NdnFchDiscovery>(options.
ndnFchUrl));
75 m_stages.push_back(make_unique<GuessFromIdentityName>(m_keyChain));
81 BOOST_ASSERT(!m_stages.empty());
82 m_stages.front()->start();
86 Procedure::connect(
const FaceUri& hubFaceUri)
89 [
this] (
const FaceUri& canonicalUri) {
90 m_controller.start<nfd::FaceCreateCommand>(
91 ControlParameters().setUri(canonicalUri.toString()),
92 [
this] (
const ControlParameters& params) {
93 std::cerr <<
"Connected to HUB " << params.getUri() << std::endl;
94 this->registerPrefixes(params.getFaceId());
96 [
this, canonicalUri] (
const ControlResponse& resp) {
97 if (resp.getCode() == 409) {
98 ControlParameters params(resp.getBody());
99 std::cerr <<
"Already connected to HUB " << params.getUri() << std::endl;
100 this->registerPrefixes(params.getFaceId());
103 std::cerr <<
"Failed to connect to HUB " << canonicalUri <<
": "
104 << resp.getText() <<
" (" << resp.getCode() <<
")" << std::endl;
109 [
this] (
const std::string& reason) {
110 std::cerr <<
"Failed to canonize HUB FaceUri: " << reason << std::endl;
117 Procedure::registerPrefixes(uint64_t hubFaceId,
size_t index)
124 m_controller.start<nfd::RibRegisterCommand>(
127 .setFaceId(hubFaceId)
130 [=] (
const ControlParameters&) {
131 std::cerr <<
"Registered prefix " <<
HUB_PREFIXES[index] << std::endl;
132 this->registerPrefixes(hubFaceId, index + 1);
134 [=] (
const ControlResponse& resp) {
135 std::cerr <<
"Failed to register " <<
HUB_PREFIXES[index] <<
": "
136 << resp.getText() <<
" (" << resp.getCode() <<
")" << std::endl;
Procedure(Face &face, KeyChain &keyChain)
signal::Signal< Procedure, bool > onComplete
Signal emitted when the procedure completes.
void initialize(const Options &options)
void runOnce()
Run the HUB discovery procedure once.
constexpr time::nanoseconds FACEURI_CANONIZE_TIMEOUT
constexpr nfd::RouteOrigin HUB_ROUTE_ORIGIN
const std::vector< Name > HUB_PREFIXES
constexpr uint64_t HUB_ROUTE_COST
std::string ndnFchUrl
HTTP base URL of NDN-FCH service.