Change the face setting, now SyncLogic SyncPolicyManager and SyncSocket share the same m_face provided by up-layer application instance.
diff --git a/src/sync-logic.cc b/src/sync-logic.cc
index eccb3fa..38b624a 100644
--- a/src/sync-logic.cc
+++ b/src/sync-logic.cc
@@ -65,6 +65,8 @@
SyncLogic::SyncLogic (const Name& syncPrefix,
shared_ptr<SyncPolicyManager> syncPolicyManager,
+ shared_ptr<Face> face,
+ shared_ptr<Transport> transport,
LogicUpdateCallback onUpdate,
LogicRemoveCallback onRemove)
: m_state (new FullState)
@@ -74,6 +76,8 @@
, m_onRemove (onRemove)
, m_perBranch (false)
, m_policyManager(syncPolicyManager)
+ , m_face(face)
+ , m_transport(transport)
#ifndef NS3_MODULE
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
, m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
@@ -87,10 +91,10 @@
#ifndef NS3_MODULE
// In NS3 module these functions are moved to StartApplication method
- m_transport = make_shared<TcpTransport>();
- m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+ // m_transport = make_shared<TcpTransport>();
+ // m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
- connectToDaemon();
+ // connectToDaemon();
shared_ptr<BasicIdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
shared_ptr<OSXPrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
@@ -109,6 +113,8 @@
SyncLogic::SyncLogic (const Name& syncPrefix,
shared_ptr<SyncPolicyManager> syncPolicyManager,
+ shared_ptr<Face> face,
+ shared_ptr<Transport> transport,
LogicPerBranchCallback onUpdateBranch)
: m_state (new FullState)
, m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
@@ -116,6 +122,8 @@
, m_onUpdateBranch (onUpdateBranch)
, m_perBranch(true)
, m_policyManager(syncPolicyManager)
+ , m_face(face)
+ , m_transport(transport)
#ifndef NS3_MODULE
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
, m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
@@ -129,10 +137,10 @@
#ifndef NS3_MODULE
// In NS3 module these functions are moved to StartApplication method
- m_transport = make_shared<TcpTransport>();
- m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+ // m_transport = make_shared<TcpTransport>();
+ // m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
- connectToDaemon();
+ // connectToDaemon();
shared_ptr<BasicIdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
shared_ptr<OSXPrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
@@ -151,32 +159,31 @@
SyncLogic::~SyncLogic ()
{
m_face->removeRegisteredPrefix(m_syncRegisteredPrefixId);
- m_face->shutdown();
}
-void
-SyncLogic::connectToDaemon()
-{
- //Hack! transport does not connect to daemon unless an interest is expressed.
- Name name("/ndn");
- shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
- m_face->expressInterest(*interest,
- bind(&SyncLogic::onConnectionData, this, _1, _2),
- bind(&SyncLogic::onConnectionDataTimeout, this, _1));
-}
+// void
+// SyncLogic::connectToDaemon()
+// {
+// //Hack! transport does not connect to daemon unless an interest is expressed.
+// Name name("/ndn");
+// shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
+// m_face->expressInterest(*interest,
+// bind(&SyncLogic::onConnectionData, this, _1, _2),
+// bind(&SyncLogic::onConnectionDataTimeout, this, _1));
+// }
-void
-SyncLogic::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
- const shared_ptr<Data>& data)
-{
- _LOG_DEBUG("onConnectionData");
-}
+// void
+// SyncLogic::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
+// const shared_ptr<Data>& data)
+// {
+// _LOG_DEBUG("onConnectionData");
+// }
-void
-SyncLogic::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
-{
- _LOG_DEBUG("onConnectionDataTimeout");
-}
+// void
+// SyncLogic::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
+// {
+// _LOG_DEBUG("onConnectionDataTimeout");
+// }
#ifdef NS3_MODULE
void
diff --git a/src/sync-logic.h b/src/sync-logic.h
index b9b3057..db28b90 100644
--- a/src/sync-logic.h
+++ b/src/sync-logic.h
@@ -87,11 +87,15 @@
*/
SyncLogic (const ndn::Name& syncPrefix,
ndn::ptr_lib::shared_ptr<SyncPolicyManager> syncPolicyManager,
+ ndn::ptr_lib::shared_ptr<ndn::Face> face,
+ ndn::ptr_lib::shared_ptr<ndn::Transport> transport,
LogicUpdateCallback onUpdate,
LogicRemoveCallback onRemove);
SyncLogic (const ndn::Name& syncPrefix,
ndn::ptr_lib::shared_ptr<SyncPolicyManager> syncPolicyManager,
+ ndn::ptr_lib::shared_ptr<ndn::Face> face,
+ ndn::ptr_lib::shared_ptr<ndn::Transport> transport,
LogicPerBranchCallback onUpdateBranch);
~SyncLogic ();
@@ -143,15 +147,15 @@
getBranchPrefixes() const;
private:
- void
- connectToDaemon();
+ // void
+ // connectToDaemon();
- void
- onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+ // void
+ // onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
+ // const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
- void
- onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
+ // void
+ // onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
void
delayedChecksLoop ();
diff --git a/src/sync-policy-manager.cc b/src/sync-policy-manager.cc
index d0850b6..d8cb1c1 100644
--- a/src/sync-policy-manager.cc
+++ b/src/sync-policy-manager.cc
@@ -26,16 +26,18 @@
SyncPolicyManager::SyncPolicyManager(const Name& signingIdentity,
const Name& signingCertificateName,
const Name& syncPrefix,
+ shared_ptr<Face> face,
+ shared_ptr<Transport> transport,
int stepLimit)
: m_signingIdentity(signingIdentity)
, m_signingCertificateName(signingCertificateName.getPrefix(signingCertificateName.size()-1))
, m_syncPrefix(syncPrefix)
, m_stepLimit(stepLimit)
{
- m_transport = make_shared<TcpTransport>();
- m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+ // m_transport = make_shared<TcpTransport>();
+ // m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
- connectToDaemon();
+ // connectToDaemon();
shared_ptr<IdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
shared_ptr<PrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
@@ -53,29 +55,29 @@
SyncPolicyManager::~SyncPolicyManager()
{}
-void
-SyncPolicyManager::connectToDaemon()
-{
- //Hack! transport does not connect to daemon unless an interest is expressed.
- Name name("/ndn");
- shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
- m_face->expressInterest(*interest,
- bind(&SyncPolicyManager::onConnectionData, this, _1, _2),
- bind(&SyncPolicyManager::onConnectionDataTimeout, this, _1));
-}
+// void
+// SyncPolicyManager::connectToDaemon()
+// {
+// //Hack! transport does not connect to daemon unless an interest is expressed.
+// Name name("/ndn");
+// shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
+// m_face->expressInterest(*interest,
+// bind(&SyncPolicyManager::onConnectionData, this, _1, _2),
+// bind(&SyncPolicyManager::onConnectionDataTimeout, this, _1));
+// }
-void
-SyncPolicyManager::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
- const shared_ptr<Data>& data)
-{
- _LOG_DEBUG("onConnectionData");
-}
+// void
+// SyncPolicyManager::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
+// const shared_ptr<Data>& data)
+// {
+// _LOG_DEBUG("onConnectionData");
+// }
-void
-SyncPolicyManager::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
-{
- _LOG_DEBUG("onConnectionDataTimeout");
-}
+// void
+// SyncPolicyManager::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
+// {
+// _LOG_DEBUG("onConnectionDataTimeout");
+// }
bool
SyncPolicyManager::skipVerifyAndTrust (const Data& data)
diff --git a/src/sync-policy-manager.h b/src/sync-policy-manager.h
index b7ec402..6a41f27 100644
--- a/src/sync-policy-manager.h
+++ b/src/sync-policy-manager.h
@@ -29,6 +29,8 @@
SyncPolicyManager(const ndn::Name& signingIdentity,
const ndn::Name& signingCertificateName,
const ndn::Name& syncPrefix,
+ ndn::ptr_lib::shared_ptr<ndn::Face> face,
+ ndn::ptr_lib::shared_ptr<ndn::Transport> transport,
int m_stepLimit = 3);
virtual
@@ -66,15 +68,15 @@
// { face_ = face; }
private:
- void
- connectToDaemon();
+ // void
+ // connectToDaemon();
- void
- onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+ // void
+ // onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
+ // const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
- void
- onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
+ // void
+ // onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
prepareIntroducerRequest(const ndn::Name& keyName,
diff --git a/src/sync-socket.cc b/src/sync-socket.cc
index 42612e0..a36d551 100644
--- a/src/sync-socket.cc
+++ b/src/sync-socket.cc
@@ -33,21 +33,22 @@
namespace Sync {
SyncSocket::SyncSocket (const string &syncPrefix,
- shared_ptr<SyncPolicyManager> syncPolicyManager,
+ shared_ptr<SyncPolicyManager> syncPolicyManager,
+ shared_ptr<Face> face,
+ shared_ptr<Transport> transport,
NewDataCallback dataCallback,
RemoveCallback rmCallback )
: m_newDataCallback(dataCallback)
, m_syncPolicyManager(syncPolicyManager)
+ , m_transport(transport)
+ , m_face(face)
, m_syncLogic (syncPrefix,
syncPolicyManager,
+ face,
+ transport,
bind(&SyncSocket::passCallback, this, _1),
rmCallback)
{
- m_transport = make_shared<TcpTransport>();
- m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
-
- connectToDaemon();
-
shared_ptr<BasicIdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
shared_ptr<OSXPrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
m_identityManager = make_shared<IdentityManager>(publicStorage, privateStorage);
@@ -55,32 +56,31 @@
SyncSocket::~SyncSocket()
{
- m_face->shutdown();
}
-void
-SyncSocket::connectToDaemon()
-{
- //Hack! transport does not connect to daemon unless an interest is expressed.
- Name name("/ndn");
- shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
- m_face->expressInterest(*interest,
- bind(&SyncSocket::onConnectionData, this, _1, _2),
- bind(&SyncSocket::onConnectionDataTimeout, this, _1));
-}
+// void
+// SyncSocket::connectToDaemon()
+// {
+// //Hack! transport does not connect to daemon unless an interest is expressed.
+// Name name("/ndn");
+// shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
+// m_face->expressInterest(*interest,
+// bind(&SyncSocket::onConnectionData, this, _1, _2),
+// bind(&SyncSocket::onConnectionDataTimeout, this, _1));
+// }
-void
-SyncSocket::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
- const shared_ptr<Data>& data)
-{
- _LOG_DEBUG("onConnectionData");
-}
+// void
+// SyncSocket::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
+// const shared_ptr<Data>& data)
+// {
+// _LOG_DEBUG("onConnectionData");
+// }
-void
-SyncSocket::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
-{
- _LOG_DEBUG("onConnectionDataTimeout");
-}
+// void
+// SyncSocket::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
+// {
+// _LOG_DEBUG("onConnectionDataTimeout");
+// }
bool
SyncSocket::publishData(const std::string &prefix, uint32_t session, const char *buf, size_t len, int freshness)
diff --git a/src/sync-socket.h b/src/sync-socket.h
index 170fde5..6fa7913 100644
--- a/src/sync-socket.h
+++ b/src/sync-socket.h
@@ -56,6 +56,8 @@
*/
SyncSocket (const std::string &syncPrefix,
ndn::ptr_lib::shared_ptr<SyncPolicyManager> syncPolicyManager,
+ ndn::ptr_lib::shared_ptr<ndn::Face> face,
+ ndn::ptr_lib::shared_ptr<ndn::Transport> transport,
NewDataCallback dataCallback,
RemoveCallback rmCallback);
@@ -88,15 +90,15 @@
GetLocalPrefix ();
private:
- void
- connectToDaemon();
+ // void
+ // connectToDaemon();
- void
- onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+ // void
+ // onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
+ // const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
- void
- onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
+ // void
+ // onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
void
passCallback(const std::vector<MissingDataInfo> &v)
@@ -134,8 +136,8 @@
SequenceLog m_sequenceLog;
ndn::ptr_lib::shared_ptr<SyncPolicyManager> m_syncPolicyManager;
ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager;
- ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport;
+ ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
SyncLogic m_syncLogic;
};