34 namespace autoconfig {
36 using nfd::ControlParameters;
37 using nfd::ControlResponse;
46 , m_keyChain(keyChain)
47 , m_controller(face, keyChain)
54 BOOST_ASSERT(m_stages.empty());
55 this->makeStages(options);
56 BOOST_ASSERT(!m_stages.empty());
58 for (
size_t i = 0; i < m_stages.size(); ++i) {
59 m_stages[i]->onSuccess.connect(bind(&Procedure::connect,
this, _1));
60 if (i + 1 < m_stages.size()) {
61 m_stages[i]->onFailure.connect([=] (
const std::string&) { m_stages[i + 1]->start(); });
64 m_stages[i]->onFailure.connect([=] (
const std::string&) { this->
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)
128 .setOrigin(HUB_ROUTE_ORIGIN)
129 .setCost(HUB_ROUTE_COST),
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;
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...