34 using nfd::ControlParameters;
35 using nfd::ControlResponse;
44 , m_keyChain(keyChain)
45 , m_controller(face, keyChain)
52 BOOST_ASSERT(m_stages.empty());
54 BOOST_ASSERT(!m_stages.empty());
56 for (
size_t i = 0; i < m_stages.size(); ++i) {
57 m_stages[i]->onSuccess.connect([
this] (
const auto& uri) { connect(uri); });
58 if (i + 1 < m_stages.size()) {
59 m_stages[i]->onFailure.connect([=] (
const auto&) { m_stages[i + 1]->start(); });
62 m_stages[i]->onFailure.connect([=] (
const auto&) {
onComplete(
false); });
68 Procedure::makeStages(
const Options& options)
70 m_stages.push_back(make_unique<MulticastDiscovery>(m_face, m_controller));
71 m_stages.push_back(make_unique<GuessFromSearchDomains>());
72 m_stages.push_back(make_unique<NdnFchDiscovery>(options.
ndnFchUrl));
73 m_stages.push_back(make_unique<GuessFromIdentityName>(m_keyChain));
79 BOOST_ASSERT(!m_stages.empty());
80 m_stages.front()->start();
84 Procedure::connect(
const FaceUri& hubFaceUri)
87 [
this] (
const FaceUri& canonicalUri) {
88 m_controller.start<nfd::FaceCreateCommand>(
89 ControlParameters().setUri(canonicalUri.toString()),
90 [
this] (
const ControlParameters& params) {
91 std::cerr <<
"Connected to HUB " << params.getUri() << std::endl;
92 this->registerPrefixes(params.getFaceId());
94 [
this, canonicalUri] (
const ControlResponse& resp) {
95 if (resp.getCode() == 409) {
96 ControlParameters params(resp.getBody());
97 std::cerr <<
"Already connected to HUB " << params.getUri() << std::endl;
98 this->registerPrefixes(params.getFaceId());
101 std::cerr <<
"Failed to connect to HUB " << canonicalUri <<
": "
102 << resp.getText() <<
" (" << resp.getCode() <<
")" << std::endl;
107 [
this] (
const std::string& reason) {
108 std::cerr <<
"Failed to canonize HUB FaceUri: " << reason << std::endl;
115 Procedure::registerPrefixes(uint64_t hubFaceId,
size_t index)
122 m_controller.start<nfd::RibRegisterCommand>(
125 .setFaceId(hubFaceId)
128 [=] (
const ControlParameters&) {
129 std::cerr <<
"Registered prefix " <<
HUB_PREFIXES[index] << std::endl;
130 this->registerPrefixes(hubFaceId, index + 1);
132 [=] (
const ControlResponse& resp) {
133 std::cerr <<
"Failed to register " <<
HUB_PREFIXES[index] <<
": "
134 << 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.