guess-from-identity-name.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
27 
28 namespace ndn {
29 namespace tools {
30 namespace autoconfig {
31 
32 GuessFromIdentityName::GuessFromIdentityName(Face& face, KeyChain& keyChain,
33  const NextStageCallback& nextStageOnFailure)
34  : BaseDns(face, keyChain, nextStageOnFailure)
35 {
36 }
37 
38 void
40 {
41  std::cerr << "Trying to find home router based on the default identity name..." << std::endl;
42 
43  Name identity = m_keyChain.getDefaultIdentity();
44 
45  std::ostringstream serverName;
46  for (auto i = identity.rbegin(); i != identity.rend(); ++i) {
47  serverName << i->toUri() << ".";
48  }
49  serverName << "_homehub._autoconf.named-data.net";
50 
51  try {
52  std::string hubUri = BaseDns::querySrvRr(serverName.str());
53  this->connectToHub(hubUri);
54  }
55  catch (const BaseDns::Error& e) {
56  m_nextStageOnFailure(std::string("Failed to find a home router based on the default identity "
57  "name (") + e.what() + ")");
58  }
59 }
60 
61 } // namespace autoconfig
62 } // namespace tools
63 } // namespace ndn
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Definition: nfd.hpp:35
NextStageCallback m_nextStageOnFailure
Definition: base.hpp:111
void connectToHub(const std::string &uri)
Attempt to connect to local hub using the uri FaceUri.
Definition: base.cpp:41
virtual void start() override
Start the stage.
std::string querySrvRr(const std::string &fqdn)
Send DNS SRV request for a fqdn fully qualified domain name.
Definition: base-dns.cpp:53
std::function< void(const std::string &)> NextStageCallback
Callback to be called when the stage fails.
Definition: base.hpp:61
Base class for stages that use DNS-based guessing.
Definition: base-dns.hpp:38
GuessFromIdentityName(Face &face, KeyChain &keyChain, const NextStageCallback &nextStageOnFailure)
Create stage to guess home router based on the default identity name.