src: Creating faces to neighbors explicitly by NLSR
Nlsr creates faces to all neighbors explicitly like nfdc create faces.
After successful creation of all faces Nlsr will proceed for further
processing. In case of failure in creating any face, Nlsr will exit
immediately by destroying the created faces.
Change-Id: If7f2ee2a406f4bfbacf0b7c51335a3dbbb44e167
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index b0d5126..68fbcc7 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -62,6 +62,10 @@
};
public:
+ typedef ndn::function<void(const ndn::nfd::ControlParameters&)> CommandSucceedCallback;
+
+ typedef ndn::function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback;
+
Nlsr()
: m_scheduler(m_nlsrFace.getIoService())
, m_confParam()
@@ -83,6 +87,10 @@
, m_certificateCache(new ndn::CertificateCacheTtl(m_nlsrFace.getIoService()))
, m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache)
+
+ , m_controller(m_nlsrFace)
+ , m_nFacesToCreate(0)
+ , m_nFacesCreated(0)
{}
void
@@ -264,6 +272,9 @@
initialize();
void
+ start();
+
+ void
intializeKey();
void
@@ -312,6 +323,15 @@
return m_defaultCertName;
}
+ void
+ createFace(const std::string& faceUri,
+ uint64_t faceCost,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure);
+
+ void
+ destroyFaces();
+
private:
void
registerPrefixes();
@@ -325,6 +345,27 @@
void
onKeyPrefixRegSuccess(const ndn::Name& name);
+ void
+ onCreateFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
+
+ void
+ onCreateFaceFailure(int32_t code, const std::string& error);
+
+ void
+ createFaces();
+
+ void
+ onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
+
+ void
+ onDestroyFaceFailure(int32_t code, const std::string& error);
+
+ void
+ destroyFace(const std::string& faceUri);
+
+ void
+ destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult);
+
private:
typedef std::map<ndn::Name, ndn::shared_ptr<ndn::IdentityCertificate> > CertMap;
@@ -354,6 +395,10 @@
ndn::KeyChain m_keyChain;
ndn::Name m_defaultIdentity;
ndn::Name m_defaultCertName;
+
+ ndn::nfd::Controller m_controller;
+ int32_t m_nFacesToCreate;
+ int32_t m_nFacesCreated;
};
} //namespace nlsr