Project

General

Profile

Task #2421

Refactor ndn-autoconfig tool

Added by Alex Afanasyev over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Category:
Tools
Target version:
Start date:
01/26/2015
Due date:
% Done:

100%

Estimated time:

Description

The code ndn-autoconfig shall be refactored to separate individual stages into separate classes. Each stage either succeeds and registers necessary prefixes or fails and calling callback to start other stages (if available).

Here is a basic design for the refactoring

Base class for the stage

/**
 * @brief Base class for discovery stages
 */
class Base
{
public
  /**
   * @brief Callback to be called when the stage fails
   */
  typedef std::function<void(const std::string&)> NextStageCallback;

  class Error : public std::runtime_error
  {
    ...
  }

  /**
   * @brief Start the stage
   */
  virtual void
  start() = 0;

protected:
  /**
   * @brief Initialize variables and create nfd::Controller instance
   * @param face Face to be used for all operations (e.g., will send registration commands)
   * @param keyChain KeyChain object
   * @param nextStageOnFailure Callback to be called after the stage failed
   */
  Base(Face& face, KeyChain& keyChain, nfd::Controller& controller,
       const NextStageCallback& nextStageOnFailure);

  /**
   * @brief Attempt to connect to local hub using the \p uri FaceUri
   * @throw Base::Error when failed to establish the tunnel
   */
  void
  connectToHub(const std::string& uri);
};

Base class for stages with DNS operations

/**
 * @brief Base class for stages that use DNS-based guessing
 */
class BaseDns : public Base
{
protected:
  /**
   * @brief Send DNS SRV request for a \p fqdn fully qualified domain name
   */
  std::pair<QueryAnswer, int/*number of answers returned*/>
  query(const std::string& fqdn);

  /**
   * @brief Send DNS SRV request using search domain list
   */
  std::pair<QueryAnswer, int/*number of answers returned*/>
  querySearch();

  /**
   * @brief Parse result of the query and connect to home hub
   */
  bool
  parseHostAndConnectToHub(QueryAnswer& queryAnswer, int answerSize);
};

Actual stage implementations

/**
 * @brief Multicast discovery stage
 *
 * - Request
 *
 *     The end host sends an Interest over a multicast face.
 *
 *     Interest Name is /localhop/ndn-autoconf/hub.
 *
 * - Response
 *
 *     A producer app on the HUB answer this Interest with a Data packet that contains a
 *     TLV-encoded Uri block.  The value of this block is the URI for the HUB, preferably a
 *     UDP tunnel.
 */
class MulticastDiscovery : public Base
{
public:
  ...
};

/**
 * @brief Guessing home router based on DNS query with default suffix
 *
 * - Request
 *
 *     The end host sends a DNS query that is equivalent to this command:
 *
 *         dig +search +short +cmd +tries=2 +ndots=10 _ndn._udp srv
 *
 * - Response
 *
 *     The DNS server should answer with an SRV record that contains the hostname and UDP port
 *     number of the NDN router.
 */
class GuessingFromSearchDomains : public BaseDns
{
public:
  ...
};


/**
 * @brief Guessing home router based on the default identity name
 *
 * This stage assumes that user has configured default certificate using
 * http://ndncert.named-data.net/
 *
 * - Request
 *
 *     The end host loads the default user identity (eg. /ndn/edu/ucla/cs/afanasev), and
 *     converts it to DNS format.
 *
 *     The end host sends a DNS query for an SRV record of name _ndn._udp. + user identity in
 *     DNS format + _homehub._auto-conf.named-data.net. For example:
 *
 *         _ndn._udp.afanasev.cs.ucla.edu.ndn._homehub._autoconf.named-data.net
 *
 * - Response
 *
 *     The DNS server should answer with an SRV record that contains the hostname and UDP port
 *     number of the home NDN router of this user's site.
 */
class GuessingFromIdentityName : public BaseDns
{
public:
  ...
};

History

#1 Updated by Alex Afanasyev over 4 years ago

  • Status changed from Code review to Closed

Also available in: Atom PDF