communication: adapt to API changes in PSync
Pass the KeyChain instance to psync::FullProducer
Change-Id: Ia97356dc364c7bdaf6dc80ad57fa351eeabe997d
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 3e29067..cd9e17a 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -20,9 +20,7 @@
*/
#include "sync-logic-handler.hpp"
-#include "common.hpp"
-#include "conf-parameter.hpp"
-#include "lsa/lsa.hpp"
+#include "hello-protocol.hpp"
#include "logger.hpp"
#include "utility/name-helper.hpp"
@@ -32,14 +30,14 @@
INIT_LOGGER(SyncLogicHandler);
-SyncLogicHandler::SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew,
- const ConfParameter& conf)
- : onNewLsa(std::make_unique<OnNewLsa>())
- , m_syncFace(face)
- , m_isLsaNew(isLsaNew)
+const std::string LSA_COMPONENT{"LSA"};
+
+SyncLogicHandler::SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
+ IsLsaNew isLsaNew, const ConfParameter& conf)
+ : m_isLsaNew(std::move(isLsaNew))
, m_confParam(conf)
, m_nameLsaUserPrefix(ndn::Name(m_confParam.getSyncUserPrefix()).append(boost::lexical_cast<std::string>(Lsa::Type::NAME)))
- , m_syncLogic(m_syncFace, m_confParam.getSyncProtocol(), m_confParam.getSyncPrefix(),
+ , m_syncLogic(face, keyChain, m_confParam.getSyncProtocol(), m_confParam.getSyncPrefix(),
m_nameLsaUserPrefix, m_confParam.getSyncInterestLifetime(),
std::bind(&SyncLogicHandler::processUpdate, this, _1, _2, _3))
{
@@ -62,7 +60,7 @@
{
NLSR_LOG_DEBUG("Update Name: " << updateName << " Seq no: " << highSeq);
- int32_t nlsrPosition = util::getNameComponentPosition(updateName, NLSR_COMPONENT);
+ int32_t nlsrPosition = util::getNameComponentPosition(updateName, HelloProtocol::NLSR_COMPONENT);
int32_t lsaPosition = util::getNameComponentPosition(updateName, LSA_COMPONENT);
if (nlsrPosition < 0 || lsaPosition < 0) {
@@ -70,9 +68,8 @@
return;
}
- ndn::Name networkName = updateName.getSubName(1, nlsrPosition-1);
+ ndn::Name networkName = updateName.getSubName(1, nlsrPosition - 1);
ndn::Name routerName = updateName.getSubName(lsaPosition + 1).getPrefix(-1);
-
ndn::Name originRouter = networkName;
originRouter.append(routerName);
@@ -109,7 +106,8 @@
"is enabled. Not going to fetch.");
return;
}
- (*onNewLsa)(updateName, seqNo, originRouter, incomingFaceId);
+
+ onNewLsa(updateName, seqNo, originRouter, incomingFaceId);
}
}
}
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 9f3e5de..6eee213 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -23,25 +23,19 @@
#define NLSR_SYNC_LOGIC_HANDLER_HPP
#include "conf-parameter.hpp"
-#include "test-access-control.hpp"
-#include "signals.hpp"
#include "lsa/lsa.hpp"
+#include "signals.hpp"
#include "sync-protocol-adapter.hpp"
-
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/util/signal.hpp>
+#include "test-access-control.hpp"
namespace nlsr {
-class ConfParameter;
-
/*! \brief NLSR-to-ChronoSync interaction point
*
* This class serves as the abstraction for the syncing portion of
* NLSR and its components. NLSR has no particular reliance on
* ChronoSync, except that the NLSR source would need to be modified
* for use with other sync protocols.
- *
*/
class SyncLogicHandler
{
@@ -55,7 +49,8 @@
using IsLsaNew =
std::function<bool(const ndn::Name&, const Lsa::Type& lsaType, const uint64_t&, uint64_t/*inFace*/)>;
- SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew, const ConfParameter& conf);
+ SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
+ IsLsaNew isLsaNew, const ConfParameter& conf);
/*! \brief Instruct ChronoSync to publish an update.
*
@@ -92,10 +87,9 @@
const ndn::Name& updateName, uint64_t seqNo, uint64_t incomingFaceId);
public:
- std::unique_ptr<OnNewLsa> onNewLsa;
+ OnNewLsa onNewLsa;
private:
- ndn::Face& m_syncFace;
IsLsaNew m_isLsaNew;
const ConfParameter& m_confParam;
@@ -105,10 +99,6 @@
ndn::Name m_coorLsaUserPrefix;
SyncProtocolAdapter m_syncLogic;
-
-private:
- const std::string NLSR_COMPONENT = "nlsr";
- const std::string LSA_COMPONENT = "LSA";
};
} // namespace nlsr
diff --git a/src/communication/sync-protocol-adapter.cpp b/src/communication/sync-protocol-adapter.cpp
index 81ec6f3..2e09d2b 100644
--- a/src/communication/sync-protocol-adapter.cpp
+++ b/src/communication/sync-protocol-adapter.cpp
@@ -22,30 +22,32 @@
#include "sync-protocol-adapter.hpp"
#include "logger.hpp"
-INIT_LOGGER(SyncProtocolAdapter);
-
namespace nlsr {
+INIT_LOGGER(SyncProtocolAdapter);
+
+#ifdef HAVE_CHRONOSYNC
const auto FIXED_SESSION = ndn::name::Component::fromNumber(0);
+#endif
SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face,
+ ndn::KeyChain& keyChain,
SyncProtocol syncProtocol,
const ndn::Name& syncPrefix,
const ndn::Name& userPrefix,
ndn::time::milliseconds syncInterestLifetime,
- const SyncUpdateCallback& syncUpdateCallback)
- : m_syncProtocol(syncProtocol)
- , m_syncUpdateCallback(syncUpdateCallback)
+ SyncUpdateCallback syncUpdateCallback)
+ : m_syncProtocol(syncProtocol)
+ , m_syncUpdateCallback(std::move(syncUpdateCallback))
{
- NLSR_LOG_TRACE("SyncProtocol value: " << m_syncProtocol);
-
+ switch (m_syncProtocol) {
#ifdef HAVE_CHRONOSYNC
- if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) {
+ case SyncProtocol::CHRONOSYNC:
NDN_LOG_DEBUG("Using ChronoSync");
m_chronoSyncLogic = std::make_shared<chronosync::Logic>(face,
syncPrefix,
userPrefix,
- std::bind(&SyncProtocolAdapter::onChronoSyncUpdate, this, _1),
+ [this] (auto&&... args) { onChronoSyncUpdate(std::forward<decltype(args)>(args)...); },
chronosync::Logic::DEFAULT_NAME,
chronosync::Logic::DEFAULT_VALIDATOR,
chronosync::Logic::DEFAULT_RESET_TIMER,
@@ -55,42 +57,55 @@
chronosync::Logic::DEFAULT_SYNC_REPLY_FRESHNESS,
chronosync::Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME,
FIXED_SESSION);
- return;
- }
+ break;
#endif
-
- NDN_LOG_DEBUG("Using PSync");
- m_psyncLogic = std::make_shared<psync::FullProducer>(80,
- face,
- syncPrefix,
- userPrefix,
- std::bind(&SyncProtocolAdapter::onPSyncUpdate, this, _1),
- syncInterestLifetime);
+ case SyncProtocol::PSYNC:
+ NDN_LOG_DEBUG("Using PSync");
+ m_psyncLogic = std::make_shared<psync::FullProducer>(face,
+ keyChain,
+ 80,
+ syncPrefix,
+ userPrefix,
+ [this] (auto&&... args) { onPSyncUpdate(std::forward<decltype(args)>(args)...); },
+ syncInterestLifetime);
+ break;
+ default:
+ NDN_CXX_UNREACHABLE;
+ }
}
void
SyncProtocolAdapter::addUserNode(const ndn::Name& userPrefix)
{
+ switch (m_syncProtocol) {
#ifdef HAVE_CHRONOSYNC
- if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) {
+ case SyncProtocol::CHRONOSYNC:
m_chronoSyncLogic->addUserNode(userPrefix, chronosync::Logic::DEFAULT_NAME, FIXED_SESSION);
- return;
- }
+ break;
#endif
-
- m_psyncLogic->addUserNode(userPrefix);
+ case SyncProtocol::PSYNC:
+ m_psyncLogic->addUserNode(userPrefix);
+ break;
+ default:
+ NDN_CXX_UNREACHABLE;
+ }
}
void
SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix, uint64_t seq)
{
+ switch (m_syncProtocol) {
#ifdef HAVE_CHRONOSYNC
- if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) {
+ case SyncProtocol::CHRONOSYNC:
m_chronoSyncLogic->updateSeqNo(seq, userPrefix);
- return;
- }
+ break;
#endif
- m_psyncLogic->publishName(userPrefix, seq);
+ case SyncProtocol::PSYNC:
+ m_psyncLogic->publishName(userPrefix, seq);
+ break;
+ default:
+ NDN_CXX_UNREACHABLE;
+ }
}
#ifdef HAVE_CHRONOSYNC
diff --git a/src/communication/sync-protocol-adapter.hpp b/src/communication/sync-protocol-adapter.hpp
index db67fb1..fb5cdbe 100644
--- a/src/communication/sync-protocol-adapter.hpp
+++ b/src/communication/sync-protocol-adapter.hpp
@@ -25,6 +25,8 @@
#include "conf-parameter.hpp"
#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
#ifdef HAVE_CHRONOSYNC
#include <ChronoSync/logic.hpp>
#endif
@@ -32,18 +34,19 @@
namespace nlsr {
-typedef std::function<void(const ndn::Name& updateName,
- uint64_t seqNo, uint64_t incomingFaceId)> SyncUpdateCallback;
+using SyncUpdateCallback = std::function<void(const ndn::Name& updateName,
+ uint64_t seqNo, uint64_t incomingFaceId)>;
class SyncProtocolAdapter
{
public:
- SyncProtocolAdapter(ndn::Face& facePtr,
+ SyncProtocolAdapter(ndn::Face& face,
+ ndn::KeyChain& keyChain,
SyncProtocol syncProtocol,
const ndn::Name& syncPrefix,
const ndn::Name& userPrefix,
ndn::time::milliseconds syncInterestLifetime,
- const SyncUpdateCallback& syncUpdateCallback);
+ SyncUpdateCallback syncUpdateCallback);
/*! \brief Add user node to ChronoSync or PSync
*
@@ -91,6 +94,7 @@
private:
SyncProtocol m_syncProtocol;
SyncUpdateCallback m_syncUpdateCallback;
+
#ifdef HAVE_CHRONOSYNC
std::shared_ptr<chronosync::Logic> m_chronoSyncLogic;
#endif